Reputation: 880
i can't understand why my code is not working; it is only displaying 1 result, whereas there are multiple entries in table..
<?php
$search = $_POST['search'];
print ($search);
$query = "SELECT * FROM student WHERE county= 'sussex'";
$result = mysql_query($query,$conn);
$counter = 0;
$z=0;
while($row = mysql_fetch_assoc($result)){
$id[$counter] = $row['roll_number'];
$counter = $counter + 1;
}
?>
<table border="1" id="table1" >
<th>Id</th>
<th>Type</th>
<th>Description</th>
<th>Operator Id</th>
<?
if($counter>0)
{
for($z=0;$z<$counter;$z++)
{
?>
<tr>
<?
if($z<$counter)
{
?>
<td >
<?php echo $id[$z]?>
</td>
<?
}
$z = $z + 1;
?>
</tr>
</table>
Upvotes: 1
Views: 5820
Reputation: 50563
You forgot to close the FOR loop and its enclosing IF, I've done it below:
<?
if($counter>0)
{
for($z=0;$z<$counter;$z++)
{
?>
<tr>
<?
if($z<$counter)
{
?>
<td >
<?php echo $id[$z]?>
</td>
<?
}
//$z = $z + 1; <!-- REMOVE or comment out this line -->
?>
</tr>
<? }
} ?> <!-- HERE we close the for loop and the IF -->
</table>
UPDATE: noted, thanks to VinceBurn, that $z was incremented twice
Upvotes: 4