Get rows from a table in different orders

The code While($row=mysql_fetch_assoc($res))returns the rows 1,2,3 ... n-1, n .

I need after getting from the same $ res (do not make a new request ) strings, but in a different order n, n-1, ..., 2,1 .

Maybe?

+4
source share
3 answers

You can use the function mysqli_data_seek().

Example:

$result = mysqli_query( $query );
$totalRows = mysqli_stmt_num_rows( $result );

for( $i=($totalRows-1); $i>=0; $i-- )
{
    mysqli_data_seek( $result, $i );
    $row = mysqli_fetch_row( $result );
}

Please note: You can mysqli_data_seekonly use after mysqli_query, mysqli_store_resultor mysqli_use_result.


+4
source

A simple inverse juste array and store it in a new variable.

<?php

  $newvar=array_reverse($array);
 ?>
+2
source

ORDER BY columnName , , , ORDER BY columnName DESC

+1

Source: https://habr.com/ru/post/1629700/


All Articles