Follow us on Twitter X-Cart on Facebook Wiki
Shopping cart software Solutions for online shops and malls
 

Random Products - 2 Products Per Row - In Place of Featured

 
Reply
   X-Cart forums > X-Cart 4 > Dev Questions > Changing design
 
Thread Tools Search this Thread
  #31  
Old 03-03-2003, 10:38 PM
 
funkydunk funkydunk is offline
 

X-Man
  
Join Date: Oct 2002
Location: Cambridge, UK
Posts: 2,210
 

Default

Really glad you like it and it works for you.
__________________
ex x-cart guru
Reply With Quote
  #32  
Old 03-17-2003, 07:33 PM
 
timtrolious timtrolious is offline
 

Newbie
  
Join Date: Mar 2003
Location: Dallas, TX
Posts: 2
 

Default

Quote:
Originally Posted by funkydunk
DogTags

On a big db you are right , this would take some processing to do this.

Another option would be (if you still wanted it sort of random) to set up some kind of rule that selected a range of products depending on the day of the week etc.

The file to amend would be the randoms.php file that I created.

I have a rather large DB myself, and the random idea is cool but I'm probably going to stick with the featured products list. However, I do like the two items idea. I was wondering how we could modify the featured products tpl to allow two items to appear on one row ? I tried doing it myself within the loop, but I can't figure out how to use smarty's code to generate my own counter variable and increment it each run, so I can use a modulus comparison to print out a </TR><TR> after every second row.

Any help would be appreciated..
__________________
Tim
Reply With Quote
  #33  
Old 03-17-2003, 10:04 PM
 
funkydunk funkydunk is offline
 

X-Man
  
Join Date: Oct 2002
Location: Cambridge, UK
Posts: 2,210
 

Default

if you use the code in http://forum.x-cart.com/viewtopic.php?p=10593#10593 this will work for featured products aswell.
__________________
ex x-cart guru
Reply With Quote
  #34  
Old 06-28-2003, 08:39 AM
 
davesphoto davesphoto is offline
 

Member
  
Join Date: May 2003
Posts: 24
 

Default

I keep getting an error with my random.php:

Quote:
Parse error: parse error, unexpected T_STRING in /www/d/davesphoto/htdocs/store/customer/random.php on line 16

my line 16 is the line with the actual rand function. Could this function be disallowed by my server? This is line 16:

Code:
б═ б═$rnd = rand(0, count($products_id)-1);

Made the switch while live (my site doesn't get much traffic yet anyway) so I would like to get this straightened out quick.

Thanks
Reply With Quote
  #35  
Old 06-28-2003, 10:44 AM
 
davesphoto davesphoto is offline
 

Member
  
Join Date: May 2003
Posts: 24
 

Default

I have got it working but I am doing the random part in the SQL query. My random.php is now:

Code:
<? // the database query $query = "SELECT * FROM $sql_tbl[products],$sql_tbl[pricing] WHERE forsale='Y' AND avail>0 AND $sql_tbl[products].productid=$sql_tbl[pricing].productid ORDER BY RAND() LIMIT 2 "; // give the product array to smarty to make it available sitewide. $randoms = func_query($query); $smarty->assign("randoms",$randoms); ?>

This seems easy enough to me, are there any drawbacks to doing it this way?

I also added the original featured products back into the random.tpl so now I can specify one or two perminant featured products (with the X-cart module) and have two random ones.

Any other sugestions? This seems too easy compared to other solutions .
Reply With Quote
  #36  
Old 06-29-2003, 01:08 AM
  70challenger's Avatar 
70challenger 70challenger is offline
 

Advanced Member
  
Join Date: May 2003
Posts: 71
 

Default

What i did i do wrong? I get this error:

Fatal error: Call to undefined function: func_query() in /home/virtual/site110/fst/var/www/html/acart/customer/random.php on line 3

I'm a little confused with random.php or randoms.php.
Reply With Quote
  #37  
Old 06-29-2003, 09:18 AM
  70challenger's Avatar 
70challenger 70challenger is offline
 

Advanced Member
  
Join Date: May 2003
Posts: 71
 

Default

Where do I put this? it seems to be the only step I cant figure out.
thanks

Quote:
Originally Posted by B00MER
Code:
$f_products = func_query("select $sql_tbl[products].*, min($sql_tbl[pricing].price) as price from $sql_tbl[products], $sql_tbl[featured_products], $sql_tbl[pricing], $sql_tbl[categories] where $sql_tbl[products].productid=$sql_tbl[featured_products].productid and $sql_tbl[pricing].productid=$sql_tbl[products].productid AND $sql_tbl[products].categoryid=$sql_tbl[categories].categoryid AND ($sql_tbl[categories].membership='$membership' OR $sql_tbl[categories].membership='') and $sql_tbl[products].forsale='Y' and $sql_tbl[products].avail>0 and $sql_tbl[featured_products].avail='Y' and $sql_tbl[pricing].quantity=1 AND $sql_tbl[featured_products].categoryid='$f_cat' and ($sql_tbl[pricing].membership='$membership' or $sql_tbl[pricing].membership='') group by $sql_tbl[products].productid order by $sql_tbl[featured_products].product_order");

Whew what a SQL query

http://www.php.net/manual/en/printwn/function.rand.php

Little mix of rand(); and some modified or added SQL queries and its possible.
Reply With Quote
  #38  
Old 07-07-2003, 11:13 AM
  70challenger's Avatar 
70challenger 70challenger is offline
 

Advanced Member
  
Join Date: May 2003
Posts: 71
 

Default

Could someone help me with this?
Reply With Quote
  #39  
Old 07-07-2003, 12:59 PM
 
toonarific toonarific is offline
 

Advanced Member
  
Join Date: Jul 2003
Posts: 92
 

Default

From this post

Code:
this is the current sql not the new stuff. the new stuff will be more complex than this. need to add this into customer/home.php Code: include "./random.php"; This will bring in a list of random products. Then we need to create this random.php in customer/ and is based on reccomends.php Code: <? // give it all available products to work with $products_id = func_query("SELECT productid FROM $sql_tbl[products] WHERE forsale='Y' and avail>0"); // set the variables $str = ""; $numberRandoms=10; // set this to how many you want to show // the witchcraft $query_condition = " AND ("; srand((double)microtime()*1000000); $rnd = rand(0, count($products_id)-1); $query_condition .= "productid='".$products_id[$rnd][productid]."'"; for($i = 0; $i < $numberRandoms - 1; $i++) { $rnd = rand(0, count($products_id)-1); if (!ereg("'".$products_id[$rnd][productid]."'", $query_condition)) { $query_condition .= " OR productid='".$products_id[$rnd][productid]."'"; } } // finish off the query $query_condition .= ")"; // runs the new random query against the database $query = "SELECT * FROM $sql_tbl[products] WHERE forsale='Y' AND avail>0".$query_condition; // give the product array to smarty to make it available sitewide. $randoms = func_query($query); $smarty->assign("randoms",$randoms); ?> You will then need to include this in the home page by modifying the appropriate templates.

Where in the home.php code does the include string go, or should it be 'require' instead of 'include'?

Should the random.php file go into the customer/ directory, or customer/main/ ?

Thanx
Reply With Quote
  #40  
Old 07-19-2003, 09:19 AM
  groovico's Avatar 
groovico groovico is offline
 

X-Man
  
Join Date: Apr 2003
Location: Firetanksoftware.com
Posts: 2,326
 

Default

Quote:
Originally Posted by davesphoto
I have got it working but I am doing the random part in the SQL query. My random.php is now:

Code:
<? // the database query $query = "SELECT * FROM $sql_tbl[products],$sql_tbl[pricing] WHERE forsale='Y' AND avail>0 AND $sql_tbl[products].productid=$sql_tbl[pricing].productid ORDER BY RAND() LIMIT 2 "; // give the product array to smarty to make it available sitewide. $randoms = func_query($query); $smarty->assign("randoms",$randoms); ?>

This seems easy enough to me, are there any drawbacks to doing it this way?

I also added the original featured products back into the random.tpl so now I can specify one or two perminant featured products (with the X-cart module) and have two random ones.

Any other sugestions? This seems too easy compared to other solutions .

Nope you did it the more efficient way. Using mysql to do the random select and limit is way more efficient than the other methods.

Also means nothing heavy happens on the database

I was reading this thread and thinking why don't they just use the mysql ORDER BY RAND() LIMIT 10.

Saves on all the counting products, randomising seeds and stuff.

Nice one.

Note to others, using ORDER BY RAND() LIMIT in any sql statement will randomise your results for you. Very handy for having random offers/news/quote showing.
__________________
Groovico

Used by X-carters the world over:
Marketing Manager Pro Bundle For X-cart
Featured Product Manager for X-cart
Feed manager pro for X-cart

http://www.firetanksoftware.com

Celebrating 7 Years of providing quality X-cart Add ons and X-cart Mods for x-cart 3.X to X-cart 4.4.X
Reply With Quote
Reply
   X-Cart forums > X-Cart 4 > Dev Questions > Changing design



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -8. The time now is 11:34 PM.

   

 
X-Cart forums © 2001-2020