X-Cart: shopping cart software

X-Cart forums (https://forum.x-cart.com/index.php)
-   Changing design (https://forum.x-cart.com/forumdisplay.php?f=51)
-   -   Random Products - 2 Products Per Row - In Place of Featured (https://forum.x-cart.com/showthread.php?t=914)

funkydunk 03-03-2003 10:38 PM

Really glad you like it and it works for you. :D

timtrolious 03-17-2003 07:33 PM

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..

funkydunk 03-17-2003 10:04 PM

if you use the code in http://forum.x-cart.com/viewtopic.php?p=10593#10593 this will work for featured products aswell.

davesphoto 06-28-2003 08:39 AM

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

davesphoto 06-28-2003 10:44 AM

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 :wink: .

70challenger 06-29-2003 01:08 AM

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.

70challenger 06-29-2003 09:18 AM

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. :wink:


70challenger 07-07-2003 11:13 AM

Could someone help me with this?

toonarific 07-07-2003 12:59 PM

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

groovico 07-19-2003 09:19 AM

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 :wink: .


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.


All times are GMT -8. The time now is 07:28 AM.

Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.