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; } } Quote 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']; 1 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.