$count++; $count = str_pad($count, 2, "0", STR_PAD_LEFT); Code (markup): Hi, I'm using this code to number query results from mysql like: 01 02 03 04 05 But I would like to number results like: 05 04 03 02 01 Can someone help me with this please?
hi, first get the total number of results : $count = mysql_num_rows($result); PHP: then show your results and place this at the bottom: $count--; $count = str_pad($count, 2, "0", STR_PAD_LEFT); PHP: U'r welcome
Make sure you place $count--; $count = str_pad($count, 2, "0", STR_PAD_LEFT); PHP: within the loop, under the echo/print function calls.
This should do it? $getcomments = mysql_query("SELECT * FROM comments"); $count = mysql_num_rows($getcomments); while($row = mysql_fetch_array($getcomments)) { $count--; $count = str_pad($count, 2, "0", STR_PAD_LEFT); echo" <b>$count</b> </div> "; } PHP: Still not working
$getcomments = mysql_query("SELECT * FROM comments"); $count = mysql_num_rows($getcomments); while($row = mysql_fetch_array($getcomments)) { $count = str_pad($count, 2, "0", STR_PAD_LEFT); echo"<b>$count</b>"; $count--; } echo"</div>"; PHP: