I'm trying to create a dynamic html table while querying the DB using PHP. I'm having a bit of difficulty understanding how to append two different loops to it to ensure the table I want to create is generated correctly.
<table><tr>
<td>$ID and $ITEM_NAME</td>
<td>$ID and $ITEM_NAME</td>
</tr>
<tr>
<td>$ID and $ITEM_NAME</td>
<td>$ID and $ITEM_NAME</td>
</tr>
<tr>
<td>$ID and $ITEM_NAME</td>
<td>$ID and $ITEM_NAME</td>
</tr></table>
<hr>
<table><tr>
<td>$ID and $ITEM_NAME</td>
<td>$ID and $ITEM_NAME</td>
</tr>
<tr>
<td>$ID and $ITEM_NAME</td>
<td>$ID and $ITEM_NAME</td>
</tr>
<tr>
<td>$ID and $ITEM_NAME</td>
<td>$ID and $ITEM_NAME</td>
</tr></table>
<hr>
As you can see I have to append two rows worth of information in to one HTML table row and on the 3rd row I need to append a
and create a new HTML table while continuing my query.
Currently my PHP code looks something like this.
foreach($item_ID as $x => $x_value) {
$sql = "SELECT item_name FROM item_table WHERE id = '$x_value'";
$query = $this -> db -> query($sql);
foreach($query->result() as $row){
$item_name = $row->item_name;
}
$html_output .= '<tr><td>';
$html_output .= $x_value. " ".$item_name;
$html_output .= '</td>';
//Not sure how to proceed with closing the rows and opening new one on 3rd query item?
}
Please note that I am using Codeigniter, however I am just looking for some help in logic.
Let me know if I can help clear things up.
Thank you for taking your time to read this. Any help would be greatly appreciated.