Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Why isn't my WHERE query working

Status
Not open for further replies.

t5amec

Programmer
Aug 14, 2003
112
GB
Code:
$query="SELECT * FROM malloysGigs ORDER BY date WHERE active='1' DESC Limit 1";

The above is the query I put at the beginning of my code. I personally can't see anything wrong with it... can you?

When i don't have rge WHERE syntax it works fine, but I need want it to show only the rows in the database where the active equals 1.

Any help?

Make Sense? I hope so (-:
 
For one thing, "DESC" doesn't make sense unless it's adjacent to an ORDER BY column name.

Also, MySQL is picky about the order of clauses. WHERE clauses need to come before ORDER BY clauses.

I'd try:

Code:
$query="SELECT * FROM malloysGigs WHERE active='1' ORDER BY date DESC Limit 1";

Want the best answers? Ask the best questions!

TANSTAAFL!!
 
thanks, big help!

Make Sense? I hope so (-:
 
Also, dont use SELECT *, but SELECT only the fields you need.

You dont have to choose the fields that you want to run the WHERE on, as you can do something like:

Code:
SELECT `uid`, `fnam`, `lnam` FROM `malloysGigs` WHERE active='1' ORDER BY `date` DESC Limit 0, 1";


Olav Alexander Mjelde
Admin & Webmaster
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top