I am trying to loop through, and display, the contents of an array
in a table cell, and loop through and display the content of a database
field in the cell next to it. I would like the database loop to continue
even though the array loop is complete.
Using the following code I am getting the contents of the array only.
I also tried reworking the code and ended up with the data side by side
as required however the rows repeated the same number of times as
there is rows in the database.
$results = $mysqli->query("SELECT message FROM contact");
echo '<table width="100%" border="1" cellspacing="0" cellpadding="0">';
$colors = array("red", "green", "blue", "yellow");
$arrlength = count($colors);
while($row = $results->fetch_assoc())
$numRows = $results->num_rows;
{
$arrlength = count($colors);
for($x = 0; $x < $arrlength; $x++) {
$colors[$x];
if ($x>$numRows){
break;
}
echo ' <tr align="center" height="40"><td>' . $colors[$x] . '</td><td>' . $row["message"] . '</td></tr>';
}
}
echo '</table>';