Hello,
What I am wanting to do is get a query from the database then do a count on a particular field on all rows. It is for a "Hot Seller" type thing. What I have is when someone orders a particular product it will add popularity to that item. What I then want to do is, for the hot seller, do a query of all products then pick out the one that has the highest popularity.
Here is my code that does the query.
// start border
sb("100%","Hot Seller",$colour_1,$colour_2);
// list 1 random product
If (!empty($cat_id))
{
$query5 = "select * from ".$prefix."store_inventory order by rand() desc LIMIT 1";
}
If (empty($cat_id))
{
$query5 = "select * from ".$prefix."store_inventory order by rand() desc LIMIT 1";
}
$result5 = mysql_query($query5);
// start table for neat display
echo"<table align=\"left\" width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"5\">";
while($row5 = mysql_fetch_array($result5)){
$title=$row5["title"];
$product=$row5["product"];
$title=stripslashes($title);
$image = $row5["image"];
$description = $row5["description"];
$description=stripslashes($description);
$description=substr($description,0,50);
if (!file_exists("$site_dir/images/" . "thumb_$image")){
$thumb=new thumbnail("$site_dir/images/$image");
$thumb->size_auto(75);
$thumb->jpeg_quality(75);
$thumb->save("$site_dir/images/thumb_$image");}
// display info
echo"<tr><td width=\"90\" align=\"left\"><a href=\"view_product.php?product=$product\" target=\"_self\"><img src=\"images/thumb_$image\" border=\"0\"></a></td>";
echo"<td align=\"left\" valign=\"top\"><a href=\"view_product.php?product=$product\" target=\"_self\"><b>$title</b></a><br><br><b>Description:</b><br>$description";
if(strlen($description)>=50)
{echo"..";}
if(empty($description))
{echo"n/a";}
echo"</td>";
echo"<td width=\"90\" align=\"left\"><a href=\"view_product.php?product=$product\"><img src=\"images/more_info.gif\" border=\"0\"></a></td>";
echo"</tr>";
}// end while
echo"</table>";
// end border
eb();
echo"<br>";
Now where I'm stumped is where and how to add the highest count thing.
Thanks for all replies.
-Blake