bear bear - 26 days ago 4x
HTML Question

Stop continuous table generation

I am trying to stop the data in the following table from continuing to repeat itself, as in looping on the same data, crashing the browser:

Here's the query:

$posts = mysqli_fetch_assoc(mysqli_query($db, "SELECT * from tbl_bugresponse WHERE bugid = $id ORDER BY time"));

And here's the table code:

<table width="100%" class="tborder">
<th class="tcat">Name</th>
<th class="tcat">Reply</th>
while($posts) {
if($colour == "1"){
echo ("<tr class='alt1'>");
$f1 = $posts['by'];
$f2 = $posts['content'];
$colour = "2";
else {
echo "<tr class='alt2'>";
$f1 = $posts['by'];
$f2 = $posts['content'];
$colour = "1";
<td><?php echo $f1; ?></td>
<td><?php echo $f2; ?></td>

Note that I am using mysqli not mysql.


You aren't progressing through the result set. mysqli_query gets your resultset, and mysqli_fetch_assoc progresses through it. You need something like this:

$results = mysqli_query($db, "SELECT * from tbl_bugresponse WHERE bugid = $id ORDER BY time");
while ($posts = mysqli_fetch_assoc($results)) {
    // table construction code goes here