Hi, again..
I was looking for a way to group different featured products, say one group for featured TVs and another featured DVDs, so the featured area is a separte entity, is this possible.
Thanks
Tony
Been playing with this, very good, have an issue that as some featured items may turn over frequently I was wondering if this could be adapted to pick products on a keyword and integrate the random version of featured?
Asking a lot (again!)
Thanks
Tony
Hi Tony,
Random based on keyword is straight forward - based on the above code have a go with:
unset($featured);
$keyword = "Widget";
$count = 3;
$sql = "SELECT name,1 AS sequence FROM `".$config_databaseTablePrefix."products` WHERE name LIKE '%".database_safe($keyword)."%' ORDER BY RAND() LIMIT ".$count;
if (database_querySelect($sql,$rows))
{
$sqlNames = array();
$sqlCase = "CASE normalised_name";
foreach($rows as $featured)
{
$featured["name"] = tapestry_normalise($featured["name"]);
$sqlNames[] = "'".$featured["name"]."'";
$sqlCase .= " WHEN '".database_safe($featured["name"])."' THEN ".$featured["sequence"];
}
$sqlCase .= " END AS sequence";
$sqlIn = implode(",",$sqlNames);
$sql = "SELECT * , MIN( price ) AS minPrice, MAX( price ) AS maxPrice, COUNT( id ) AS numMerchants, ".$sqlCase." FROM `".$config_databaseTablePrefix."products` WHERE normalised_name IN (".$sqlIn.") GROUP BY normalised_name ORDER BY sequence";
database_querySelect($sql,$rows);
$featured["products"] = $rows;
foreach($featured["products"] as $k => $product)
{
$featured["products"][$k]["productHREF"] = tapestry_productHREF($product);
$featured["products"][$k]["reviewHREF"] = tapestry_reviewHREF($product);
}
}
if (isset($featured)) require("html/featured.php");
Simply change the $keyword and $count as required at lines 2/3...
Cheers,
David.
--
PriceTapestry.com
Hi,
I get this error:
Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in /home/*******/public_html/includes/database.php on line 27
Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in /home/*******/public_html/includes/database.php on line 32
any pointers??
Sorry Tony, replacement SQL should have been
$sql = "SELECT name,1 AS sequence FROM `".$config_databaseTablePrefix."products` WHERE name LIKE '%".database_safe($keyword)."%' ORDER BY RAND() LIMIT ".$count;
(RAND should have been RAND() and also $keyword made database safe) Corrected above also...
Cheers,
David.
--
PriceTapestry.com
Perfect fix, just one last thing!
Is there a way to change the title used from 'Featured Products' to a string set in the above code i.e. 'Featured DVDs'
Thanks again
Tony
Hi Tony,
Sure - keeping consistency with the way that the script sets an array variable named after the html/ file included, on the second line of the code, immediately after:
unset($featured);
add...
$featured["title"] = "Featured DVDs";
And then in html/featured.php, look for the following code at line 4:
<th colspan='<?php print count($featured["products"]); ?>'><?php print translate("Featured Products"); ?></th>
...and REPLACE with:
<th colspan='<?php print count($featured["products"]); ?>'><?php print (isset($featured["title"])?$featured["title"]:translate("Featured Products")); ?></th>
Cheers,
David.
--
PriceTapestry.com
superb, great fix and running already.
Very impressed with support...
David,
I followed the above instructions putting featured products from different keywords searches from within a category but I can't seem to get this part to work:
<?php
print (isset($featured["title"])?$featured["title"]:translate("Featured Products");
?>
I get this error:
Parse error: syntax error, unexpected ';' in /htdocs/www/html/featured.php on line 9
line 9 is the line this code is on. Is this valid code?
Hi trodat,
Sorry yes there was a syntax error in that section - the correct version is
<?php print (isset($featured["title"])?$featured["title"]:translate("Featured Products")); ?>
(also corrected in code above)
Cheers,
David.
--
PriceTapestry.com
Hi David,
I would like to use the code mentioned above to create different landing pages with different types of featured products.
When I put your code snippet in the latest version of the index.php and replace everything from "$sql = "SELECT * FROM..." to "if (isset($featured)) require("html/featured.php");" with it, I receive the following error:
Parse error: syntax error, unexpected T_VARIABLE in /www/htdocs/pt/index.php on line 34 => $featured["name"] = tapestry_normalise($featured["name"]);
Do I have to adapt the code for the latest version?
Thank you and best regards
Bernhard
Hi Bernhard,
There was a missing semi-colon on the preceding line; should be:
$featured["name"] = str_replace($section."/","",$featured["name"]);
All working OK as above, no changes required for latest distribution.
Cheers,
David.
--
PriceTapestry.com
Hi Tony,
There's an easy mod to add Featured Product "sections". As you would presumably want to show more than one section (possibly on the same page) I'll post the complete selection code which you can then use where required.
unset($featured);
$section = "DVD";
$sql = "SELECT * FROM `".$config_databaseTablePrefix."featured` WHERE name LIKE '".$section."/%' ORDER BY sequence";
if (database_querySelect($sql,$rows))
{
$sqlNames = array();
$sqlCase = "CASE normalised_name";
foreach($rows as $featured)
{
$featured["name"] = str_replace($section."/","",$featured["name"]);
$featured["name"] = tapestry_normalise($featured["name"]);
$sqlNames[] = "'".$featured["name"]."'";
$sqlCase .= " WHEN '".database_safe($featured["name"])."' THEN ".$featured["sequence"];
}
$sqlCase .= " END AS sequence";
$sqlIn = implode(",",$sqlNames);
$sql = "SELECT * , MIN( price ) AS minPrice, MAX( price ) AS maxPrice, COUNT( id ) AS numMerchants, ".$sqlCase." FROM `".$config_databaseTablePrefix."products` WHERE normalised_name IN (".$sqlIn.") GROUP BY normalised_name ORDER BY sequence";
database_querySelect($sql,$rows);
$featured["products"] = $rows;
foreach($featured["products"] as $k => $product)
{
$featured["products"][$k]["productHREF"] = tapestry_productHREF($product);
$featured["products"][$k]["reviewHREF"] = tapestry_reviewHREF($product);
}
}
if (isset($featured)) require("html/featured.php");
With that in place, prefix your Featured Products with a section name followed by "/", for example:
DVD/Product 1
DVD/Product 2
TV/Product 1
TV/Product 2
...and in the code above, simply change the section name on the first line to match the section name required...
Cheers,
David.
--
PriceTapestry.com