LioMandi Posted June 26, 2007 Posted June 26, 2007 In the product_info.php I want to display the # of purchases made for a product . Is there a way to define this? Ex: # of Downloads : 2333 or # of Purchases: 2333
gazzzzzza Posted June 28, 2007 Posted June 28, 2007 You would need to run a new database query to extract the information of how many times that item has been purchased, then output it on screen. You could count how many 'orders' the product has been purchased in, or how much quantity has been ordered, or both. Off the top of my head, it would be something like: <?php if($products_id > 0) { $bought_query = 'SELECT products_quantity FROM orders_products WHERE products_id =\''.$products_id.'\''; $bought_result = mysql_query($bought_query); $bought_num_rows = mysql_num_rows($bought_result); if(!$bought_num_rows) { echo 'This item has not previously been sold.'; } $bought_quantity = 0; while($bought_row = mysql_fetch_array($bought_result)) { $bought_quantity = $bought_quantity+$bought_row['products_quantity']; } if($bought_quantity > 0) { echo '# of purchases: '.$bought_quantity; } } ?> That should do it I think. It won't be the most efficient script ever, but its late and I'm tired! Let me know how you get on, and if you need it to do anything else. I'm not sure on the downloads side of things, but it shouldn't be too hard to factor that in also. Have fun! always here to offer some useless advice....
Recommended Posts
Archived
This topic is now archived and is closed to further replies.