Question: 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!

PHP Help! I am trying to display my name, id, and price

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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!