Jump to content

Query table problem


graham23s

Recommended Posts

Hi Guys,

 

i'm having trouble getting my query right! what i want to do is group the customers by product image, the product name (then if they have bough 20 over X weeks the total here)

 

My attempt:

 

$qO = "SELECT `PRODUCT_ID`, SUM(QUANTITY) as `QTY` FROM `fcp_orders_master_log` WHERE `CUSTOMER_ID`='$cusID'";

 

full code:

 

<?php
  case "pmr":
  
   // GRAB THE CUSTOMERS ID
   $cusID = $_GET['customer-id'];
   
     // SEE IF THERE ARE ANY ORDER WITH THIS ID
     $qO = "SELECT `PRODUCT_ID`, SUM(QUANTITY) as `QTY` FROM `fcp_orders_master_log` WHERE `CUSTOMER_ID`='$cusID'";
     $rO = mysql_query($qO);
     
       // DISPLAY OR DON'T DISPLAY
       if (mysql_num_rows($rO) > 0)
       {
       
        print("<table width=\"95%\" cellpadding=\"5\" cellspacing=\"1\" class=\"tbl_login\">\n");
        print("<tr>\n");
        print("<td colspan=\"4\" align=\"left\" class=\"c3\"><b>Patient Medication Record - ( $cusID )</b></td>\n");
        print("</tr>\n");
        print("<tr>\n");
        print("<td class=\"c3\"><b>Image</b></td><td class=\"c3\"><b>Name</b></td><td class=\"c3\"><b>Quantity</b></td><td class=\"c3\"><b>Date</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><td align=\"left\"><img src=\"images/pixel.gif\" width=\"1\" height=\"1\"></td>\n");
        print("</tr>\n");
        
         // LOOP
         while ($aO = mysql_fetch_array($rO))
         {
         
         // VARS
         $pmrPID = $aO['PRODUCT_ID'];
         $pmrDAT = $aO['DATE_ADDED']; 
         $pmrQTY = $aO['QTY']; 
         
           // GET THE PRODUCTS IMAGE
           $pI = "SELECT * FROM `fcp_products` WHERE `id`='$pmrPID'";
           $rI = mysql_query($pI);
           $aI = mysql_fetch_array($rI);
           
           // VARS
           $productID    = $aI['id']; 
           $productImage = $aI['product_thumbnail']; 
           $productName  = $aI['product_name'];  
         
         // ALTERNTE ROWS
         $row_color = ($row_color == "class=\"no_color\"") ? "class=\"c1\"" : "class=\"no_color\"";

         // PRINT ROWS
         print("<tr><td class=\"font_for_forms\" align=\"center\"><img src=\"products/thumbnails/$productImage\"></td><td class=\"font_for_forms\" align=\"left\"><a class=\"smart_links\" href=\"product-information.php?productid=$productID\">$productName</a></td><td class=\"font_for_forms\" align=\"center\">$pmrQTY</td><td class=\"font_for_forms\" align=\"center\">$pmrDAT</td></tr>\n");
         
         }
        
        // END THE TABLE
        print("</table>");
       
       } else {
       
         print("<div id=\"msg-no-orders\" align=\"center\">This customer hasn't placed any orders.</div>");
       
       }
  
  break;  
?>

 

MYSQL Image:

 

http://img509.imageshack.us/my.php?image=67079994xs4.jpg

 

thanks for any help guys

 

Graham

Link to comment
https://forums.phpfreaks.com/topic/136250-query-table-problem/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.