Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

PHP Help! I am trying to display my name, id, and price results (show at the top) into the built in table but I am

PHP Help! I am trying to display my name, id, and price results (show at the top) into the built in table but I am only getting the last item. How do I All of the products and rows into the table? Thanks for helping!

image text in transcribed

PHP code:

//Connect to the database (defined in dbconn.php) db_connect($username,$password);

// Select all categories in database $cquery = "SELECT CategoryID, CategoryName FROM Categories"; $cresult = mysqli_query($connection,$cquery);

$numCat = mysqli_num_rows($cresult);

if ($numCat == 0) { echo "

There are no categories of products in the database!
"; } else {

echo "

Grocery Store Categories and Products

"; for($i=0; $i";

// now find the products $pquery = "SELECT Name, ProductID, Price FROM Products WHERE CategoryID=$catID "; $presult = mysqli_query($connection,$pquery);

// get the number of products $numProds = mysqli_num_rows($presult); for($j=0; $j

// get the product information $prodName = get_mysqli_result($presult, $j, "Name"); $ProductID = get_mysqli_result($presult, $j, "ProductID"); $Price = get_mysqli_result($presult, $j, "Price");

// output it echo " $prodName $Price (id=$ProductID)
"; } echo "
"; } // end while }

db_close(); ?>

Header"; ?> "; for($c=0; $c$name$r$c"; //here is where i think the problem is. } echo ""; } ?>

No Name Store Grocery Store Categories and Products Dairy (id-1) Eggs, grade A, (1 doz.) 1.9150 (id Dai-1) Milk, whole, (1.0 gal.) 3.2127 (id-Dai-2) American cheese, (1.0 lb.) 4.3000 (id-Dai-3) Cheddar cheese, (1.0 lb.) 5.2967 (id-Dai-4) Ice cream, (1/2 gal.) 4.7103 (id Dai-5) Dairy Items Ice cream, (1/2 gal.)000 Ice cream, (1/2 gal.)010 Ice cream, (1/2 gal.)020 Ice cream, (1/2 gal.)001 Ice cream, (1/2 gal.)011 Ice cream, (1/2 gal.)02.1 Ice cream, (1/2 gal.)030Ice cream, (1/2 gal.)031 Ice cream, (1/2 gal.)032 Ice cream, (1/2 gal.)002 Ice cream, (1/2 gal.)012 Ice cream, (1/2 gal.)022 No Name Store Grocery Store Categories and Products Dairy (id-1) Eggs, grade A, (1 doz.) 1.9150 (id Dai-1) Milk, whole, (1.0 gal.) 3.2127 (id-Dai-2) American cheese, (1.0 lb.) 4.3000 (id-Dai-3) Cheddar cheese, (1.0 lb.) 5.2967 (id-Dai-4) Ice cream, (1/2 gal.) 4.7103 (id Dai-5) Dairy Items Ice cream, (1/2 gal.)000 Ice cream, (1/2 gal.)010 Ice cream, (1/2 gal.)020 Ice cream, (1/2 gal.)001 Ice cream, (1/2 gal.)011 Ice cream, (1/2 gal.)02.1 Ice cream, (1/2 gal.)030Ice cream, (1/2 gal.)031 Ice cream, (1/2 gal.)032 Ice cream, (1/2 gal.)002 Ice cream, (1/2 gal.)012 Ice cream, (1/2 gal.)022

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Data Management Databases And Organizations

Authors: Richard T. Watson

3rd Edition

0471418455, 978-0471418450

More Books

Students also viewed these Databases questions

Question

What is the Definition for Third Normal Form?

Answered: 1 week ago

Question

Provide two examples of a One-To-Many relationship.

Answered: 1 week ago