prohor Posted December 11, 2017 Share Posted December 11, 2017 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 More sharing options...
Barand Posted December 11, 2017 Share Posted December 11, 2017 If you want the names in descending order then "ORDER BY name DESC" in your query instead of id. Avoid using extract(), it's too easy to overwrite variables. Instead echo $row['name']; Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.