Jump to content

Displaying cart contents


graham23s

Recommended Posts

Hi Guys,

 

on my site i coded in the option for the admins to see what users have added to there shopping carts:

 

image:

 

http://img95.imageshack.us/my.php?im...tepointpf5.jpg

 

as you can see in the attached image it loops out the customers name and the word: Products in cart: foreach product, i ultimately wanted only the name and products in cart shown once, i know its because im looping them but im not sure how to get shot of that bit lol

 

my code:

 

<?php

case "orders-in-cart":
  
  ###########################
  # ORDERS IN CART          #######################################################################
  ###########################
  
   // See what people have in there carts
   $q_sneak = "SELECT DISTINCT `customer_id`,`product_id` FROM `fcp_orders` ORDER BY `customer_id` DESC";
   $r_sneak = mysql_query($q_sneak);
  
   $last_customer = 0;

     // Loop them out
     while ($a_sneak = mysql_fetch_array($r_sneak))
     {
      
       // Customers id
       $cus_id = $a_sneak['customer_id'];
       $cus_pt = $a_sneak['product_id'];

       // check if this is a new customer
       if ($cus_id != $last_customer)
       {
         // if he is, and he isn't the first, end the last table
         if ($last_customer != 0)
         {
            print("</table>\n<br />\n");
         }

         // start a new table
         print("<table class='tbl_products' width='95%' border='0' cellpadding='5' cellspacing='0' />\n");
         print("<tr>\n");
         print("<td align='left' colspan='2' bgcolor='#f1f1f1'><b>ID - [$cus_id]</b></td><td bgcolor='#f1f1f1'> </td>\n");
         print("</tr>\n");
       }

       // Query customer details
       $q_c = "SELECT * FROM `fcp_customers` WHERE `id`='$cus_id'";
       $r_c = mysql_query($q_c);
       $a_c = mysql_fetch_array($r_c);

       // Vars
       $c_fn = $a_c['first_name'];
       $c_ln = $a_c['last_name'];
       
       // Query the product details
       $q_p = "SELECT * FROM `fcp_products` WHERE `id`='$cus_pt'";
       $r_p = mysql_query($q_p);
       $a_p = mysql_fetch_array($r_p);
       
       // Vars
       $p_im = $a_p['product_thumbnail'];
     
       print("<tr>\n");
       print("<td colspan='2' align='left' width=\"15%\">Customers Name:</td><td align=\"left\">$c_fn $c_ln</td>\n");
       print("</tr>\n");        
       print("<tr>\n");
       print("<td colspan='2' align='left' valign='top' width=\"15%\">Products in cart:</td><td align=\"left\"><img src=\"products/thumbnails/$p_im\"></td>\n");
       print("</tr>\n");

       // change this current customer to be the last customer
       $last_customer = $cus_id;
     
     }
     
     // end table
     print("</table>\n<br /><br />");
     
  break;
?>

 

any help would be appreciated :)

 

thanks guys

 

Graham

Link to comment
https://forums.phpfreaks.com/topic/123479-displaying-cart-contents/
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.