php - PDO ORDER BY not working on fields that are not auto increment -
this question has answer here:
here code:
$q = $db->prepare("select * slider page = :page order index asc"); $q->bindvalue(':page', basename($_server['php_self'])); $q->execute(); if ($q->rowcount() > 0){ $result = $q->fetchall(pdo::fetch_assoc); ($i=0; $i < $q->rowcount(); $i++) { $path = $result[$i]['path']; echo "<div><img src=\"$path\"></div>"; } }
as is, there no result being shown. if order different field, namely 'id' auto increment , primary key of table, results ordered correct field.
'index' reserved word in mysql. if want use column name , in queries must surround ticks.
select * `slider` `page` = :page order `index` asc
Comments
Post a Comment