Xtremer360 Posted December 28, 2008 Share Posted December 28, 2008 Notice how the rowheading has its own class and so does row1 and row2 well what I want to do if I have like 10 or so rows. I want it to have the first result returned with row2 as stated in the code and then the second returned result to have row1 class and then after that it'll alternate the next would be row2 and then 4th would be row1 and so on. How do I tell it to alternate. function directory() { $query = "SELECT * FROM users"; $result = @mysql_query ($query);// Run The Query if ($result) { print'<h1 class=backstage>Active Handler Directory</h1><br />'; print'<table width="100%" class="table1">'; print'<tr class="rowheading">'; print'<td>Name</td>'; print'<td>Forum Name</td>'; print'<td>Characters</td>'; print'</tr>'; // Fetch and print all records. while ($row = mysql_fetch_array ($result, MYSQL_ASSOC)) { print'<tr class=row2>'; print'<td valign=top>Admin 1 (site admin)</td>'; print'<td valign=top>Forum Name </td>'; print'<td valign=top><ul class=characters><li>Character Name</li>'; print'</ul></td>'; print'</tr>'; print'<tr class=row1>'; print'<td valign=top>User 1</td>'; print'<td valign=top>Forum Name </td>'; print'<td valign=top><ul class=characters><li>Character Name</li>'; print'</ul></td>'; print'</tr>'; print'</table><br />'; print'<h2 class=backstage><form method=POST><input type=hidden name=action value=mainmenu><input type=submit value="Return to Main Menu" class=button200></form></h2>'; } Quote Link to comment Share on other sites More sharing options...
premiso Posted December 28, 2008 Share Posted December 28, 2008 You want to use modulus. $i=0; while ($row = mysql_fetch_array ($result, MYSQL_ASSOC)) { $class = ($i%2==0)?'row1':'row2'; print'<tr class=' . $class . '>'; print'<td valign=top>Admin 1 (site admin)</td>'; print'<td valign=top>Forum Name </td>'; print'<td valign=top><ul class=characters><li>Character Name</li>'; print'</ul></td>'; print'</tr>'; print'<tr class=' . $class . '>'; print'<td valign=top>User 1</td>'; print'<td valign=top>Forum Name </td>'; print'<td valign=top><ul class=characters><li>Character Name</li>'; print'</ul></td>'; print'</tr>'; print'</table><br />'; print'<h2 class=backstage><form method=POST><input type=hidden name=action value=mainmenu><input type=submit value="Return to Main Menu" class=button200></form></h2>'; $i++; } I am unsure why you displaying a table each loop but that is the idea behind it. Quote Link to comment 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.