Jump to content

How to show data from mysql database in decending order using pdo?


prohor

Recommended Posts

I am trying to show data using  "fetch(PDO::FETCH_desc" for show from descending order but it only works for assoc order like bellow code, how I can show it in descending order? I am new to php and pdo, please help.

$stmt = $DB_con->prepare(" SELECT name, id FROM class  ORDER BY id DESC  LIMIT 1, {$recordsPerPage}");
    $stmt->execute();
    echo $name;
   
    if($stmt->rowCount() > 0)
       
    {
        while($row=$stmt->fetch(PDO::FETCH_ASSOC))
        
        {
            extract($row);
            
            echo $name;
            
        }
    }
           
Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.