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 7712179
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T01:33:52+00:00 2026-06-01T01:33:52+00:00

I’ve managed to get one stock table to display in the cart page when

  • 0

I’ve managed to get one stock table to display in the cart page when the user selects an item to purchase but I can’t figure out how to get more than one table from different pages to display.
Any help would be appreciated!

    <?php
   session_start();
   $cart=$_SESSION["cart"];

   extract($_POST);
   if (IsSet($productid)||IsSet($_SESSION["notempty"])) $empty=false;
   else $empty=true;

   if (!$empty)
   {
      if (IsSet($cart[$productid])) $cart[$productid]+=$quantity;
      else $cart[$productid]=$quantity;
      $_SESSION["notempty"]=true;
   }

   $_SESSION["cart"]=$cart;

   $conn=mysql_connect("","");
   mysql_select_db("webent",$conn);
   mysql_query("CREATE TABLE Stock (stock_ID INT(3) NOT NULL PRIMARY KEY AUTO_INCREMENT,
                                    itemName VARCHAR(50),itemDesc VARCHAR(100),
                                    itemImage VARCHAR(10),itemStock VARCHAR(3),
                                    itemPrice VARCHAR(5))");
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" dir="ltr">

<head>
   <title>Jus' Books</title>
   <link href="style2.css" rel="stylesheet" type="text/css" />
</head>

<body>

<div id="container">

   <div id="masthead">

   </div>

   <div id="navigation">
      <p><a href="index1.php">Home</a>
      <a href="fiction.php">Fiction</a>
      <a href="travel.php">Travel</a>
      <a href="sport.php">Sport</a>
      <a href="arts.php">Arts & Design</a>
      <a href="cart.php">Shopping Cart</a>
      <a href="account.php">Manage Account</a></p>
   </div>

   <div id="content">

      <?php

      if ($empty) echo "<h4>Your shopping cart is empty</h4>";
      else
      {
         echo "<h4>Your shopping cart contains:</h4>";
         $total="";
         foreach ($cart as $id=>$no)
         {
            if ($id!="")
            {
               $result=mysql_query("SELECT * FROM Stock WHERE stock_ID= $id");
               $row=mysql_fetch_array($result);
               extract($row);



               if ($itemStock<$no) $no=$itemStock;

               echo "<p>$no units of item $itemName at $itemPrice each</p>";
            }
            $total+=$no*$itemPrice;
         }
         echo "<p>Total to pay: £$total</p>";
      }

      ?>

      <a href="index1.php">Continue Shopping</a>
      <a href="checkout.php">Proceed to Checkout</a>
      <p></p>

   </div>

   <div id="footer">
      <p><a href="index1.php">Home</a> | 
      <a href="fiction.php">Fiction</a> |
      <a href="travel.php">Travel</a> |
      <a href="sport.php">Sport</a> |
      <a href="arts.php">Arts & Design</a> |
      <a href="cart.php">Shopping Cart</a> |
      <a href="account.php">Manage Account</a></p>
   </div>

</div>

</body>

</html>

The other tables have the exact same fields but have the name Stock_Travel
Stock_Sport
Stock_Arts

  • 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-06-01T01:33:54+00:00Added an answer on June 1, 2026 at 1:33 am

    I can’t figure out how to get more than one table from different pages to display

    What do you mean by that? If you want to select from different tables, alter the query:

    $result=mysql_query("SELECT * FROM Stock_Travel WHERE stock_ID= $id");
    $result=mysql_query("SELECT * FROM Stock_Sport WHERE stock_ID= $id");
    $result=mysql_query("SELECT * FROM Stock_Arts WHERE stock_ID= $id");
    

    I hope this is some kind of homework assignment, since it’s full of tiny flaws that wouldn’t be nice in a production environment.

    As you see, the database layout is far from optimal. Why isn’t Travel/Sport/Arts stored in a Category field in the Stock table? That way you don’t have to alter your query based on the kind of product page you’re on.

    Furthermore, I wouldn’t rely on extract(), but that’s personal. You definitely will want to escape your queries, or rather use prepared statements.

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

Sidebar

Related Questions

I need to clean up various Word 'smart' characters in user input, including but
I'm making a simple page using Google Maps API 3. My first. One marker
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I want to count how many characters a certain string has in PHP, but
I am trying to understand how to use SyndicationItem to display feed which is
I have a jquery bug and I've been looking for hours now, I can't
Basically, what I'm trying to create is a page of div tags, each has
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am reading a book about Javascript and jQuery and using one of the

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.