note 74631 added to control-structures.for
| From: | jrgpmaster at gmail dot com | Date: | Fri, 20 Apr 2007 21:03:51 +0000 |
| Subject: | note 74631 added to control-structures.for | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-125716@lists.php.net to get a copy of this message | ||
This is an even easier method of using alternating row colors using the 'for' statement.
<?php
echo '
<style type="text/css">
.alt {
background-color: #ccc;
}
';
$sql = mysql_query("select * from
users");
echo '<table>';
echo '<tr><th>Name</th></tr>';
for ($i = 0; $u = mysql_fetch_array($sql); $i++)
{
$row_color = ($i % 2) ? 'alt' : '';
echo '
<tr class="'.$row_color.'">
<td>'.stripslashes($u['name']).'</td>
</tr>
';
}
echo "\n</table>";
?>
----
Server IP: 69.39.81.135
Probable Submitter: 68.18.56.9
----
Manual Page -- http://www.php.net/manual/en/control-structures.for.php
Edit -- https://master.php.net/note/edit/74631
Del: integrated -- https://master.php.net/note/delete/74631/integrated
Del: useless -- https://master.php.net/note/delete/74631/useless
Del: bad code -- https://master.php.net/note/delete/74631/bad+code
Del: spam -- https://master.php.net/note/delete/74631/spam
Del: non-english -- https://master.php.net/note/delete/74631/non-english
Del: in docs -- https://master.php.net/note/delete/74631/in+docs
Del: other reasons-- https://master.php.net/note/delete/74631
Reject -- https://master.php.net/note/reject/74631
Search -- https://master.php.net/manage/user-notes.php