I am using a table to iterate the data from the database in a table. my html code is
<table id="tablesorter">
<thead>
<tr>
<th>Name</th>
<th>Location</th>
<th>Email</th>
<th>Phone</th>
</tr>
</thead>
<tbody>
<tr>
<td>Your Name</td>
<td>Somewhere</td>
<td>test@test.com</td>
<td>9999999999</td>
</tr>
<tr class="trow">
<td>Your Name</td>
<td>Somewhere</td>
<td>test@test.com</td>
<td>9999999999</td>
</tr>
</tbody>
</table>
In my HTML table i am using a class for a table row to style it for every second table row. now while fetching the data from the database i want to make sure it does the same thing. it should add the class trow for every second table row.
what would be the logic behind this using with while loop?
Seems to me that you could just use a ternary statement to set and unset the class variable as it loops through printing each row:
So that each time a row is printed the
$classvariable would toggle betweentrowand nothing.I use this logic when creating lists that export to excel quite often