ORDER BY DESC
am 20.06.2011 21:56:04 von Chris Stinemetz
I have the bellow sql query. What is the correct way to add ORDER BY
posts.post_date DESC
I would like to add it to the end of my query, but I am just getting a
blank page or my added "query doesn't work" echo:
"The posts could not be displayed, please try again later."
The query is:
//fetch the posts from the database
$posts_sql = "SELECT
posts.post_store,
posts.post_content,
posts.post_date,
posts.post_by,
users.user_id,
users.user_name
FROM
posts
LEFT JOIN
users
ON
posts.post_by = users.user_id
WHERE
posts.post_store = " . mysql_real_escape_string($_GET['id']);
Thank you in advance for your help.
Chris
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Re: ORDER BY DESC
am 20.06.2011 22:20:02 von Gavin Chalkley
--0016363b8cecd6eab404a62a75f7
Content-Type: text/plain; charset=ISO-8859-1
Chris,
Try this:
http://dev.mysql.com/doc/refman/5.0/en/order-by-optimization .html
On 20 June 2011 20:56, Chris Stinemetz wrote:
> I have the bellow sql query. What is the correct way to add ORDER BY
> posts.post_date DESC
>
> I would like to add it to the end of my query, but I am just getting a
> blank page or my added "query doesn't work" echo:
>
> "The posts could not be displayed, please try again later."
>
> The query is:
>
> //fetch the posts from the database
> $posts_sql = "SELECT
> posts.post_store,
> posts.post_content,
> posts.post_date,
> posts.post_by,
> users.user_id,
> users.user_name
> FROM
> posts
> LEFT JOIN
> users
> ON
> posts.post_by =
> users.user_id
> WHERE
> posts.post_store = " .
> mysql_real_escape_string($_GET['id']);
>
>
>
> Thank you in advance for your help.
>
> Chris
>
> --
> PHP Database Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
--
Best regards,
Gavin C
--0016363b8cecd6eab404a62a75f7--
Re: ORDER BY DESC
am 20.06.2011 22:49:36 von Karl DeSaulniers
Try..
$posts_sql = "SELECT posts.post_store, posts.post_content,
posts.post_date, posts.post_by, users.user_id, users.user_name FROM
posts LEFT JOIN users ON osts.post_by = users.user_id WHERE
posts.post_store = " .mysql_real_escape_string($_GET['id'])." ORDER
BY posts.post_date DESC";
Karl DeSaulniers
Design Drumm
http://designdrumm.com
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Re: ORDER BY DESC
am 20.06.2011 22:53:00 von Chris Stinemetz
On Mon, Jun 20, 2011 at 3:49 PM, Karl DeSaulniers wrote:
> Try..
>
> $posts_sql = "SELECT posts.post_store, posts.post_content, posts.post_date,
> posts.post_by, users.user_id, users.user_name FROM posts LEFT JOIN users ON
> osts.post_by = users.user_id WHERE posts.post_store = "
> .mysql_real_escape_string($_GET['id'])." ORDER BY posts.post_date DESC";
>
Got it working thanks everyone who responded.
Working query:
$posts_sql = "SELECT
posts.post_store,
posts.post_content,
posts.post_date,
posts.post_by,
users.user_id,
users.user_name
FROM
posts
LEFT JOIN
users
ON
posts.post_by = users.user_id
WHERE
posts.post_store = " . mysql_real_escape_string($_GET['id']) . "
ORDER BY
posts.post_date DESC ";
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php