Sorry if this seems like a dumb question but I'm new to this kind of approach. What I have is a series of meal items that correspond with meals. At the moment my code links two tables together through the `meal_id` and runs through the selected records in a loop. What it's doing that I don't like is giving each meal item the associated row record of the meal, when they should be grouped if they correspond to the same meal ID. I already have the query initiated through `$result` I just can't get the meal items to group together as one meal.

Anything you can do to help would be fantastic!

The database return is as follows:

```
mysqli_result Object
(
    [current_field] => 0
    [field_count] => 11
    [lengths] => 
    [num_rows] => 140
    [type] => 0
)

```

Here is my code...

```
<?php
    while($row = mysqli_fetch_assoc($result))
{
    ?>
<tr>

<td align='center'><?php echo($row['meal_id']);?></td>
<td align='center'><?php echo($row['user_id']);?></td>
<td align='center'><?php echo(date("d/m/Y", strtotime($row['meal_date'])));?></td>
<td align='center'><?php echo(date("g:i A", strtotime($row['meal_time'])));?></td>
<td align='center'><?php echo($row['meal_notes']);?></td>

</tr>

```

I would like to loop the below `<tr>` for each meal item, then go on to the next meal 

```
    <tr><td align='center'><?php echo($row['meal_item_name']);?></td>
<td align='center'><?php echo($row['meal_item_measure']);?></td>
<td align='center'><?php echo($row['meal_item_measurement']);?></td>
</tr>
<?php
}
?>

```

Currently I get:

```
   |meal_id  user_id  |  meal_date  |  meal_time  |  meal_notes  |
    |meal_item_name  |  meal_item_measure | meal_item_measurement  |
    |meal_id  user_id  |  meal_date  |  meal_time  |  meal_notes  |
    |meal_item_name  |  meal_item_measure | meal_item_measurement  |
    |meal_id  user_id  |  meal_date  |  meal_time  |  meal_notes  |
    |meal_item_name  |  meal_item_measure | meal_item_measurement  |
    |meal_id  user_id  |  meal_date  |  meal_time  |  meal_notes  |
    |meal_item_name  |  meal_item_measure | meal_item_measurement  |
    |meal_id  user_id  |  meal_date  |  meal_time  |  meal_notes  |
    |meal_item_name  |  meal_item_measure | meal_item_measurement  |

```

But what I want to get it

```
|meal_id  |  user_id  |  meal_date  |  meal_time  |  meal_notes  |
|meal_item_name   |  meal_item_measure  | meal_item_measurement  |
|meal_item_name   |  meal_item_measure  | meal_item_measurement  |
|meal_item_name   |  meal_item_measure  | meal_item_measurement  |

|meal_id |   user_id  |  meal_date  |  meal_time  |  meal_notes  |
|meal_item_name   |  meal_item_measure |  meal_item_measurement  |

|meal_id  |  user_id  |  meal_date  |  meal_time  |  meal_notes  |
|meal_item_name   |  meal_item_measure | meal_item_measurement   |
|meal_item_name   |  meal_item_measure | meal_item_measurement   |

```

etc :-)