ngreenwood6 Posted December 8, 2008 Share Posted December 8, 2008 I have the following code: while($incomplete_row = mysql_fetch_array($incomplete_results)) { echo "<tr>"; echo "<td>" . $incomplete_row['school'] . "</td>"; echo "</tr>"; echo "<tr>"; echo "<th>Name</th>"; echo "<th>Request</th>"; echo "<th>Classroom</th>"; echo "<th>Date</th>"; echo "<th>Time</th>"; echo "</tr>"; //make the date $date = date("d/m/Y", $incomplete_row['date']); //make the time $time = date("h:i:s A", $incomplete_row['date']); echo "<tr>"; echo "<td>" . $incomplete_row['name'] . "</td>"; echo "<td>" . $incomplete_row['request'] . "</td>"; echo "<td>" . $incomplete_row['classroom'] . "</td>"; echo "<td>" . $date . "</td>"; echo "<td>" . $time . "</td>"; echo "<td><a href=\"view.php?id=" . $incomplete_row['id'] . "\">View</a>"; echo "</tr>"; echo "</table>"; } The problem is that for every entry it makes a whole new table. I want the school name at the top and then the "<th>" and then the listings. can someone please help. Quote Link to comment https://forums.phpfreaks.com/topic/136117-solved-while-loop-help/ Share on other sites More sharing options...
premiso Posted December 8, 2008 Share Posted December 8, 2008 $i=0; while($incomplete_row = mysql_fetch_array($incomplete_results)) { if ($i == 0) { echo "<tr>"; echo "<td>" . $incomplete_row['school'] . "</td>"; echo "</tr>"; echo "<tr>"; echo "<th>Name</th>"; echo "<th>Request</th>"; echo "<th>Classroom</th>"; echo "<th>Date</th>"; echo "<th>Time</th>"; echo "</tr>"; $i++; } //make the date $date = date("d/m/Y", $incomplete_row['date']); //make the time $time = date("h:i:s A", $incomplete_row['date']); echo "<tr>"; echo "<td>" . $incomplete_row['name'] . "</td>"; echo "<td>" . $incomplete_row['request'] . "</td>"; echo "<td>" . $incomplete_row['classroom'] . "</td>"; echo "<td>" . $date . "</td>"; echo "<td>" . $time . "</td>"; echo "<td><a href=\"view.php?id=" . $incomplete_row['id'] . "\">View</a>"; echo "</tr>"; } echo "</table>"; Try that. Quote Link to comment https://forums.phpfreaks.com/topic/136117-solved-while-loop-help/#findComment-709796 Share on other sites More sharing options...
ngreenwood6 Posted December 8, 2008 Author Share Posted December 8, 2008 Thanks for the help. That is really useful. Quote Link to comment https://forums.phpfreaks.com/topic/136117-solved-while-loop-help/#findComment-709830 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.