unemployment Posted February 8, 2011 Share Posted February 8, 2011 How do I tell php to add first and last class at the beginning and end of a while loop. <?php while (($e_row = mysql_fetch_assoc($e_query)) !== false) { ?> <li class="companyname first last"> blah </li> <?php } ?> Quote Link to comment Share on other sites More sharing options...
Roman Fedorov Posted February 8, 2011 Share Posted February 8, 2011 Use http://php.net/manual/en/function.mysql-num-rows.php to know how much rows you are going to write, then keep a counter variable, when it is 1 then write the "first" when it is the rows number write "last" Quote Link to comment Share on other sites More sharing options...
lastkarrde Posted February 8, 2011 Share Posted February 8, 2011 Get the number of results returned using mysql_num_rows, then keep a count of a variable (eg $i) and increment it in the loop. Then in the loop if($i == 0) { //first } if($i == result from numrows) { // last } 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.