1

I currently have this line of code, which works perfectly:

$data2 = mysql_query("SELECT * FROM notes WHERE HiveID=" . $HiveID) or die(mysql_error());

I want to reverse the order of my listing, so I tried adding the ORDER BY after WHERE. I tried the following code:

$data2 = mysql_query("SELECT * FROM notes WHERE HiveID=" . $HiveID  . "ORDER BY Date DESC") or die(mysql_error());

This code gave me the error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'BY Date DESC' at line 1.

I am unaware of how I can get this to work, and any help will be greatly appreciated.

1
  • You know the MySQL extension has been deprecated, right? You should not be writing code with this extension. Use PDO or MySQLi instead Commented Dec 3, 2012 at 3:12

2 Answers 2

4

You are missing a space after the open quotes.

Should be . $hive . " ORDER BY...

Sign up to request clarification or add additional context in comments.

1 Comment

I though it was going to be something simple, but I didn't think it was something that small. Thank you for your help and very fast response.
1

your query is HiveID=" . $HiveID . "ORDER which will be like 5ORDER (if hiveid is 5) so it wont give you result there must be a space before the ORDER try

"SELECT * FROM notes WHERE HiveID=" . $HiveID." ORDER BY Date DESC"

or

"SELECT * FROM notes WHERE HiveID='".$HiveID."' ORDER BY Date DESC"

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.