Jump to content

PHP page layout when query result returns multiple rows


akabod

Recommended Posts

I'm trying to write a php page that displays data from a JOIN query for a specific ID

 

table view

 

brandinfo

 

ID, brand, discounttype

 

1, antioni, no discount

 

brandproducts

 

brandID, producttype, price

 

1, Tshirt, 20.00

1, Pants, 30.00

1, Shoe, 40.00

 

 

the returned result is

 

1 antioni, no discount, Tshirt, 20.00,

2 antioni, no discount, Pants, 30.00

3 antioni, no discount, Shoe 40.00

 

The way I want the page to be displayed is

 

------------------

 

 

Antioni (at the top)

 

Table

 

1. Tshirt 20.00

2. Pants 30.00

3. Shoe 40.00

 

 

no discount (at the bottom)

----------------------------

 

How should I construct the PHP page from the result since they're retrieved as rows?

It may not be the best way but I recently did something similar by nesting while statements from 3 queries:

while($row = mysqli_fetch_array($name)){

    //Display name

  while($row = mysqli_fetch_array($data)){

    //display data

    while($row = mysqli_fetch_array($discount)){

    // display discount

It may not be the best way but I recently did something similar by nesting while statements from 3 queries:

while($row = mysqli_fetch_array($name)){

    //Display name

  while($row = mysqli_fetch_array($data)){

    //display data

    while($row = mysqli_fetch_array($discount)){

    // display discount

 

 

Thanks! That's exactly what I'm looking for.

Archived

This topic is now archived and is closed to further replies.

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