March 14, 201115 yr Hi, im echo'ing some data from my database using sql and php. <?php $blog_url="blog";//config url of aw_blog $write = Mage::getSingleton('core/resource')->getConnection('core_write'); $readresult=$write->query("SELECT title, created_time, identifier, post_content FROM aw_blog WHERE status=1 LIMIT 5");//select from db last 5 post echo "<ul>"; while ($row = $readresult->fetch() ) { echo "<li>"; echo "<div class='postTitle'><h2><a href='$blog_url/" . $row['identifier'] . "'>" . $row['title'] . "</a></h2>"; echo "<h3>" . $row['created_time'] . "</h3></div>"; echo "<div class='postContent'>" . substr($row['post_content'], 0, 250) . "</div>"; echo "</li>"; } echo "</ul>"; ?> The above works fine however its listing old entries where id like to list recent ones. Usually id use something like this to set the order ... ORDER BY identifier So putting that into the above should look like .. $readresult=$write->query("SELECT title, created_time, identifier, post_content FROM aw_blog ORDER BY identifier WHERE status=1 LIMIT 5");//select from db last 5 post When i add the above my sql query stops working so i must have something wrong ?
March 14, 201115 yr Change to: $readresult=$write->query("SELECT title, created_time, identifier, post_content FROM aw_blog WHERE status=1 ORDER BY identifier LIMIT 5");//select from db last 5 post ORDER BY needs to go after the WHERE clause.
March 14, 201115 yr Author Just spent an hour on that little error !! Well at least ill know for next time. Thanks henbast rep added ;-)
Create an account or sign in to comment