Siobhan Sykes Siobhan Sykes - 10 days ago 6
PHP Question

For loop not working in PHP script

I have written a PHP script to pull data from a SQL database to display on a webpage. Everything seems fine but when I run the script it throws the error:


Parse error: syntax error, unexpected ')', expecting ';' in db_data.php on line 21


Line 21 is my FOR loop, I have checked the syntax of the loop and it seems to be correct so I can't understand why it is failing.

$result = mysqli_query($con,"SELECT * igi");

echo "<table border='1'>
<tr>
<th>Ref</th>
<th>Nameame</th>
<th>Location</th>
<th>Email</th>
<th>Issue</th>
<th>Urgency</th>
</tr>";

for($row = mysqli_fetch_array($result)){
echo "<tr>";
echo "<td>" . $row['REF'] . "</td>";
echo "<td>" . $row['NAME'] . "</td>";
echo "<td>" . $row['LOCATION'] . "</td>";
echo "<td>" . $row['EMAIL'] . "</td>";
echo "<td>" . $row['ISSUE'] . "</td>";
echo "<td>" . $row['URGENCY'] . "</td>";
echo "</tr>";
}
echo "</table>";

mysqli_close($con);

Answer

Change for to while

<?php
//                   Missing FROM here vv
$result = mysqli_query($con,"SELECT * FROM igi");

echo "<table border='1'>
<tr>
<th>Ref</th>
<th>Nameame</th>
<th>Location</th>
<th>Email</th>
<th>Issue</th>
<th>Urgency</th>
</tr>";

while($row = mysqli_fetch_array($result)){
   echo "<tr>";
   echo "<td>" . $row['REF'] . "</td>";
   echo "<td>" . $row['NAME'] . "</td>";
   echo "<td>" . $row['LOCATION'] . "</td>";
   echo "<td>" . $row['EMAIL'] . "</td>";
   echo "<td>" . $row['ISSUE'] . "</td>";
   echo "<td>" . $row['URGENCY'] . "</td>";
   echo "</tr>";
}
echo "</table>";

mysqli_close($con);
Comments