graham23s Posted October 30, 2008 Share Posted October 30, 2008 Hi Guys, hers a snap shot of my database: http://img261.imageshack.us/my.php?image=dbeq4.jpg i'm trying to make a basic statistics page, where the product and how many of eanch product has been sold! <?php case "products-statistics": // select all the products sold $q_sold = "SELECT DISTINCT(`PRODUCT_ID`) FROM `fcp_orders_master_log` ORDER BY `QUANTITY` DESC"; $r_sold = mysql_query($q_sold); if (mysql_num_rows($r_sold) < 1) { print("<span class=\"msg_nothing_here\">No product statistics to display.</span>"); include("inc/inc-footer.php"); exit; } else { // display the products print("<table width='95%' border='0' cellpadding='5' cellspacing='1' class='tbl_login' />\n"); print("<tr>\n"); print("<td colspan='3' align='left' class='c3'><b>Products & quantity sold to date.</b></td>\n"); print("</tr>\n"); print("<tr>\n"); print("<td align=\"center\" class='c3'><b>Product Image</b></td><td align=\"center\" class='c3'><b>Product Description</b></td><td align=\"center\" class='c3'><b>Quantity Sold</b></td>\n"); print("</tr>\n"); print("<tr class=\"c5\">\n"); print("<td align=\"left\"><img src=\"images/pixel.gif\" width=\"1\" height=\"1\"></td><td align=\"left\"><img src=\"images/pixel.gif\" width=\"1\" height=\"1\"></td><td align=\"left\"><img src=\"images/pixel.gif\" width=\"1\" height=\"1\"></td>\n"); print("</tr>\n"); while ($p_row = mysql_fetch_array($r_sold)) { // vars $pid = $p_row['PRODUCT_ID']; $pqy = $p_row['QUANTITY']; // find out what the products were $qP = "SELECT * FROM `fcp_products` WHERE `ID`='$pid'"; $rP = mysql_query($qP); $aP = mysql_fetch_array($rP); // more vars $p_th = $aP['product_thumbnail']; $p_nm = $aP['product_name']; // print rows... print("<tr><td align=\"center\"><img src=\"products/thumbnails/$p_th\"></td><td align=\"left\"><a class=\"smart_links\" href=\"product-information.php?productid=$pid\">$p_nm</a></td><td align=\"center\"><span class=\"cart_price\">$pqy</span></td></tr>"); } print("</table>"); } ?> this query: <?php $q_sold = "SELECT DISTINCT(`PRODUCT_ID`) FROM `fcp_orders_master_log` ORDER BY `QUANTITY` DESC"; ?> so we have sold 10 of product 243 it shsows up in the table! right now it shows individually! thanks for any help guys Graham Link to comment https://forums.phpfreaks.com/topic/130780-help-with-query/ Share on other sites More sharing options...
Barand Posted October 30, 2008 Share Posted October 30, 2008 SELECT `PRODUCT_ID`, SUM(quantity) as qty FROM `fcp_orders_master_log` GROUP BY PRODUCT_ID ORDER BY qty DESC Link to comment https://forums.phpfreaks.com/topic/130780-help-with-query/#findComment-678750 Share on other sites More sharing options...
graham23s Posted October 30, 2008 Author Share Posted October 30, 2008 thanks a ton barry Graham Link to comment https://forums.phpfreaks.com/topic/130780-help-with-query/#findComment-678756 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.