Loop through html table (for each tr)
I need to be able to loop through an HTML table and output data. In each <tr>
there is 8 td
's. The first td
is a dropdown menu of engineers. The next 7 td
s are days of the week with drop downs for time slots.
I'm basically building a scheduler output for a specific internal app. (that's irrelevant here).
So, here's an example table:
<table width="200" border="1">
<tr>
<th scope="col">Engineer</th>
<th scope="col">Monday</th>
<th scope="col">Tuesday</th>
<th scope="col">Wednesday</th>
<th scope="col">Thursday</th>
<th scope="col">Friday</th>
<th scope="col">Saturday</th>
<th scope="col">Sunday</th>
</tr>
<tr>
<td>John Doe</td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> &l开发者_如何学编程t;/td>
<td> </td>
<td> </td>
</tr>
<tr>
<td>Jane Doe</td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
</tr>
</table>
Each td
has a form element and each tr
is a "section" of data. In the end I will have 20+ tr
's and need to be able to run through each tr
and grab the relavant data from these, however, I need to be able to iterate through each tr
so that I can manage the code better.
Is there a way to do this with PHP?
echo '<table width="100%" border="0"><tr>';
echo '<td width="20px"></td>';
echo '<td align="left"><strong>Title</strong></td>';
echo '<td align="center" width="125px"><strong>Posted</strong></td>';
$sql = 'SELECT SQL_CALC_FOUND_ROWS * FROM `announcement` ORDER BY `id` DESC LIMIT '.$search['start'].', '.$search['max'];
$rows = $mysql_conn->fetch_array($sql);
foreach($rows as $key=>$record) {
echo (($key+1)%2) ? '<tr bgcolor="#AEDEFF" >' : '<tr>';
echo '<td align="left"><input class="checkbox" type="checkbox" name="delete[]" id="delete[]" value="'.$record["id"].'" /></td>';
echo '<td align="left"><a href="?page=cpanel&module=announcement&task=edit&id='.$record["id"].'">'. $record["title"] .'</a></td>';
echo '<td align="center">'.$record["datetime"].'</td></tr>';
}
echo '</table>';
Example of what I use when I want to output a list of rows with columns of data. Not sure if this is what you want but it works. :)
精彩评论