Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7177699
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T16:46:08+00:00 2026-05-28T16:46:08+00:00

I’ve been pondering over this one for a while and can’t think how to

  • 0

I’ve been pondering over this one for a while and can’t think how to execute.

Problem – I have built a cart mechanism which is working well and storing each item in the database with ROW (id_cart, id_session, id_product, product_name, qty_product, cart_price, cart_size, cart_variety, date_added). The current output is great however, when two items appear in the table with the same id_session and id_product I want to not repeat the product_name except add a second row to the qty_product, cart_size, cart_variety and sub total line.

Related build_cart.php is as follows;

$display_block = '<div id="heading">Your Order</div>';

// Set cart subtotal to zero
$subtotal = 0;

//check for cart items based on user session id
$get_cart_sql = "SELECT * FROM store_cart WHERE id_session = '".$_COOKIE["PHPSESSID"]."'";
$get_cart_res = mysqli_query($dbConnect, $get_cart_sql) or die(mysqli_error($dbConnect));

if (mysqli_num_rows($get_cart_res) < 1) {
    //print message
    $display_block .= '
    <div id="body"><div style="text-align:center; padding:10px; font-weight:bold;">Your cart is currently empty</div>';
} else {
    //get info and build cart display
    $display_block .= '<div id="body">';

    while ($cart_info = mysqli_fetch_array($get_cart_res)) {
        $id_cart = $cart_info['id_cart'];
        $product_name = stripslashes($cart_info['product_name']);
        $product_price = $cart_info['cart_price'];
        $qty_product = $cart_info['qty_product'];
        $size = $cart_info['cart_size'];
        $variety = $cart_info['cart_variety'];
        $product_total = sprintf("%.02f", $product_price * $qty_product);

        $display_block .= '
        <div>
            <div id="cart_item">'.$product_name.'</div>
            <div id="edit_remove"><a href="cart_remove.php?cartitem='.$id_cart.'">remove</a> | <a href="cart_edit.php?cartitem='.$id_cart.'">edit</a></div>
        </div>
        <br/>
        <br/>
        <div>
            <div id="qty">'.$qty_product.' X '.$size.'</div>
            <div id="cart_price">&#163;'.$product_total.'</div>
        </div>
        <br/>
        <br/>';

        $subtotal += $product_total;

    }

$display_block .= '</div>'; // Here to close "CART EMPTY div

$display_block .= '
<br/>

    <div id="sub_body">

                        <div>
                          <div id="sub_titles">Cart Subtotal</div>
                          <div id="sub_price">&#163;'.$subtotal.'</div>
                        </div>
                        <div>
                          <div id="sub_titles">Delivery</div>
                          <div id="sub_price">FREE</div>
                        <br/>
                        <div>
                          <div id="sub_titles">VAT</div>
                          <div id="sub_price">&#163;'.$subtotal*0.2.'</div>
                        </div>
                        <div>
                          <div id="total">Order Total</div>
                          <div id="total_price">&#163;'.$subtotal*1.2.'</div>
                        </div>                   
    </div>

    <div id="checkout">CHECKOUT</div>';

}

echo $display_block;
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T16:46:09+00:00Added an answer on May 28, 2026 at 4:46 pm

    Changing your select to:

    SELECT 
        *, SUM(qty_product) AS total_qty
    FROM 
        store_cart
    WHERE id_session = 'your session id'
    GROUP BY id_product
    

    This will select all rows with 'your session id' group duplicate rows with the same id_product and SUM will add them together in to total quantity.

    Documentation for some reference

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a jquery bug and I've been looking for hours now, I can't
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
this is what i have right now Drawing an RSS feed into the php,
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
Does anyone know how can I replace this 2 symbol below from the string
I have this code to decode numeric html entities to the UTF8 equivalent character.
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.