Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialMike Hansen
Python Web Development Techdegree Student 3,419 PointsShow posts descending from newest to oldest
Hi guys, i am currently making a website for a customer. And he want's to show all posts he's making from newest to oldest. And i thought peace of cake! Well.. I ran into some problems. I doesn't show anything at all. I tried doing the same thing as i did in my comment section where again, it's showing the newest and the older ones down.
This is my code: <?php $query = "SELECT * FROM posts"; $query = "ORDER BY post_author DESC "; $all_posts_query = mysqli_query($connection, $query);
while($row = mysqli_fetch_assoc($all_posts_query)) {
$post_id = $row['post_id'];
$post_title = $row['post_title'];
$post_author = $row['post_author'];
$post_date = $row['post_date'];
$post_image = $row['post_image'];
?> Hope you can help me out :)
2 Answers
Mike Hansen
Python Web Development Techdegree Student 3,419 PointsNeither of them works Peter? The first one make's the posts totally dissapear, the second one is still showing newest posts in the bottom
Peter Hatzer
20,837 PointsApologize the first one should have a space on it like so :
<?php
$query = "SELECT * FROM posts";
$query . = " ORDER BY post_author DESC ";
?>
I just notice you ordering by author, would you not order by post_date or post_id? Or is there more then one author?
Mike Hansen
Python Web Development Techdegree Student 3,419 PointsWell Peter i added your code like
$query = "SELECT * FROM posts"; $query . = " ORDER BY post_date DESC ";
And then it's giving me an HTTP ERROR 500 why?
Peter Hatzer
20,837 PointsPeter Hatzer
20,837 PointsHi Mike,
Your query needs a space between it this is probably reason why its not working. Plus am sure its pulling the $query variable as u have not concatenated it. Try this: