manalnor Posted April 6, 2010 Share Posted April 6, 2010 Hello dear friends, if we have following lines line x line y line z we call it from database as $lines by help of "Pikachu2000" he mention the following code for auto-numbering the lines $i = 1; while( $array = mysqli_fetch_assoc($result) { echo $i . " - " . $lines; $i ++; } now it will shows as 1- line x 2- line y 3- line z the question here is there anyway to reverse it with keeping the order of lines, i mean to be 3- line x 2- line y 1- line z Hope you got my questions thanks in advance Quote Link to comment Share on other sites More sharing options...
trq Posted April 6, 2010 Share Posted April 6, 2010 $i = 3; while( $array = mysqli_fetch_assoc($result) { echo $i . " - " . $lines; $i--; } Quote Link to comment Share on other sites More sharing options...
manalnor Posted April 6, 2010 Author Share Posted April 6, 2010 it makes the lines goes in negative (-) 3- line x 2- line y 1- line z then if more -1 - line q -2 - line u ect Quote Link to comment Share on other sites More sharing options...
Pikachu2000 Posted April 6, 2010 Share Posted April 6, 2010 You just need to figure out where to start the numbering with a simple query to set the initial value of $i . $query = "SELECT index FROM tbl_name WHERE some_field = 'some_value'"; $result = mysqli_query($dbc, $query); $i = mysqli_num_rows($result); while( $array = mysqli_fetch_assoc($result) ) { echo $i . " - " . $array['index']; $i --; } 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.