开发者

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 tds 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>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;&l开发者_如何学编程t;/td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
  </tr>
  <tr>
    <td>Jane Doe</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</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&amp;module=announcement&amp;task=edit&amp;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. :)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜