thomashw Posted January 10, 2008 Share Posted January 10, 2008 If you look at the function, it's counting the session "cart." <? include("dbinfo.php"); $product_ids = implode(',', $_SESSION['cart']); $query = mysql_query("SELECT * FROM feature_product, feature_group, feature_item WHERE feature_product.feature_product_id IN (". $product_ids .") AND feature_group.feature_product_id=feature_product.feature_product_id AND feature_item.feature_group_id=feature_group.feature_group_id"); for($i=0; $i < count($_SESSION['cart']); $i++) { while($order = mysql_fetch_array($query)) { echo '<tr><td class="cartcontent"><br />'; echo $order['feature_product_sku']; echo '</td><td class="cartcontent"><br />'; echo $order['feature_product_name']; echo '</td><td class="cartcontent"><br />'; echo $order['feature_product_price']; echo '</td><td class="cartcontent"><br />'; echo '</td></tr>'; }} ?> When I'm echoing things, it rely's on the number of rows from three different tables (feature_product, feature_group, feature_item.) Since products can have more than one group and item, it's sometimes echoing the same thing more than once. How can I make the loop just count the number of rows in the session from the feature_product table? Quote Link to comment https://forums.phpfreaks.com/topic/85455-solved-counting-number-of-items-in-specific-row/ Share on other sites More sharing options...
teng84 Posted January 10, 2008 Share Posted January 10, 2008 men you post this again it has been moved .. ok explain your table relationships so that we know how to query it properly Quote Link to comment https://forums.phpfreaks.com/topic/85455-solved-counting-number-of-items-in-specific-row/#findComment-436061 Share on other sites More sharing options...
thomashw Posted January 10, 2008 Author Share Posted January 10, 2008 men you post this again it has been moved .. ok explain your table relationships so that we know how to query it properly It was moved? I thought I posted it in the wrong section, so I asked a mod to delete it. The tables work like this, there is a feature_product table (like a hat) which relates to a feature_group table (options for the hats - like colour, etc.) which relates to the feature_item table (options for the colour - like red, blue, green, etc.) So I only want it to count the number of rows in the feature_product table for that session. Since it's counting the number of rows in all three tables, and there are multiple options for a product, it's looping more than once for each product. Quote Link to comment https://forums.phpfreaks.com/topic/85455-solved-counting-number-of-items-in-specific-row/#findComment-436062 Share on other sites More sharing options...
teng84 Posted January 10, 2008 Share Posted January 10, 2008 this? $query = mysql_query("SELECT count(* ), * FROM feature_product, feature_group, feature_item WHERE feature_product.feature_product_id IN (". $product_ids .") AND feature_group.feature_product_id=feature_product.feature_product_id AND feature_item.feature_group_id=feature_group.feature_group_id group by feature_product_id"); Quote Link to comment https://forums.phpfreaks.com/topic/85455-solved-counting-number-of-items-in-specific-row/#findComment-436067 Share on other sites More sharing options...
thomashw Posted January 10, 2008 Author Share Posted January 10, 2008 I actually didn't need to add the count, but just added the GROUP BY. Thank you very much! Quote Link to comment https://forums.phpfreaks.com/topic/85455-solved-counting-number-of-items-in-specific-row/#findComment-436071 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.