Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

sql query customer products


YePix

Recommended Posts

Hello guys and girls, could someone help me with a query? I would like to list all previously bought products of a customer but do not get value. I tried the data from the table orders and orders_products together but does not work properly.

Link to comment
Share on other sites

something like this should give you a list of what a customer has ordered

SELECT * FROM orders_products,orders where orders.customers_id = 3 AND orders.orders_id

if run as a query in phpMyadmin it should list values of order as well as all other related data! Just be carfull and backup first. Naturaly change the customer id to the customer you are after!

will give list like this

image.png.da1e2edcda2c8556dfc0dacfa75cc33f.png

 

Link to comment
Share on other sites

<?php 
$customers_products_query_raw = "SELECT * FROM orders_products, orders where orders.customers_id =  ". (int)$_GET['customers_id'] ."  AND orders.orders_id";
while ($customers_products = tep_db_fetch_array($customers_products_query_raw)) {
echo $customers_products['products_name'];
}?>

 unfortunately no result

Link to comment
Share on other sites

@YePix

(reformatted for clarity)

 1 <?php
 2 
 3    $customers_products_query_raw = "SELECT *
 4                                     FROM orders_products,
 5                                          orders
 6                                     where orders.customers_id =  ". (int)$_GET['customers_id'] ."  
 7                                       AND orders.orders_id";
 8
 9    while ($customers_products = tep_db_fetch_array($customers_products_query_raw)) {
10       echo $customers_products['products_name'];
11    }
12 
13 ?>

While I realize you used the code provided by @JcMagpie , to me, it looks like you have an issue in line 7. What is orders.orders_id supposed to be equal to?

M

Link to comment
Share on other sites

So far, I have the query hinbekommen. I would now like the products that appear multiple times to be displayed individually with the number of times they were purchased. Someone here who can help me?

<?php 
$customers_products_query_raw = tep_db_query("select * from " . TABLE_ORDERS . " o, " . TABLE_ORDERS_PRODUCTS . " op where customers_id = '" . (int)$customer_id . "' and op.products_id and o.orders_id = op.orders_id");
//$customers_products = tep_db_fetch_array($customers_products_query_raw);
while ($customers_products = tep_db_fetch_array($customers_products_query_raw)) {
?>
<div>
<?php echo $customers_products['products_name'];?>
</div>
<?php }?>

 

Link to comment
Share on other sites

The query for the purchased products is now ready.

<?php $customers_products_query_raw = tep_db_query("select * from " . TABLE_ORDERS . " o, " . TABLE_ORDERS_PRODUCTS . " op where o.customers_id = '" . (int)$customer_id . "' and op.products_id and o.orders_id = op.orders_id group by op.products_name");
while ($customers_products = tep_db_fetch_array($customers_products_query_raw)) {
$products = '<a href="' . tep_href_link('product_info.php', 'products_id=' . $customers_products['products_id']) . '">' . $customers_products['products_name'] . '</a>'; 
?>

<?php 
echo $products;
}
?>

could someone help me with the query for the number of products for a customer's purchased products ?

product A = 6
product b = 3
product c = 7

I can not get on with this query

<?php
$customers_products_query = tep_db_query("select count(*) as number_of_products from " . TABLE_ORDERS . " o, " . TABLE_ORDERS_PRODUCTS . " op where o.customers_id = '" . (int)$customer_id . "' and o.orders_id as op_orders_id and op.products_id");
$products = tep_db_fetch_array($customers_products_query);
$count = $products['number_of_products'];
?>
<?php echo $count;?>

 

Link to comment
Share on other sites

Archived

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

×
×
  • Create New...