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 Link to comment https://forums.phpfreaks.com/topic/197702-reverse-auto-numbering/ 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--; } Link to comment https://forums.phpfreaks.com/topic/197702-reverse-auto-numbering/#findComment-1037548 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 Link to comment https://forums.phpfreaks.com/topic/197702-reverse-auto-numbering/#findComment-1037549 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 --; } Link to comment https://forums.phpfreaks.com/topic/197702-reverse-auto-numbering/#findComment-1037554 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.