Jump to content

[SOLVED] Counting number of items in specific row


thomashw

Recommended Posts

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?

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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");

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.