Hi all
I am trying to retieve some data from my database and display it in a table.
The table should have 3 columns and the number of rows depends on the amount of items retrieved
But my code is returning an infinite loop 🙁
<?php
$conn = mysql_connect('localhost','root','') or die (" could not connect to db");
$selectdb= mysql_select_db('testdb')or die (" could not connect to db");
$query = "select * from data";
$result = mysql_query($query) or die ("query error");
$result2 = mysql_num_rows($result);//got number of rows
?>
<table border = "1>
<tr>
<?php
$counter = 0;
while ($counter <=$result2 )
{
for ($j=0;$j<3;$j++)
{
$data = mysql_fetch_row($result);
?>
<td><?php echo $data[1] . "<br>" ;
$counter=counter + 1;
?></td>
<?php
}
?>
</tr>
<tr>
<?php
}
?>
</tr>
</table>
Thanks