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?

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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