Jump to content

PHP/MySQL Issue


esahp

Recommended Posts

I have:
[code]
$query = "SELECT * FROM users WHERE 1 AND WHERE `status` = '1'";
[/code]
and get the error:
[quote]
Query failed: 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 'WHERE `status` = '1'' at line 1
[/quote]

How do I get this working correctly?
Link to comment
https://forums.phpfreaks.com/topic/22058-phpmysql-issue/
Share on other sites

Well, I'm completely new to the SQL language, and I was told [b]WHERE 1[/b] lists all of the data in the table and I was looking around and found [b]WHERE `blah` = 'blah'[/b] Which I assumed to mean [b]WHERE [u]field[/u] equals [u]blah[/u][/b].
So basically, I'm wanting to to list all of the data in the table [b]users[/b] where the field [b]status[/b] is equal to [b]1[/b]
Link to comment
https://forums.phpfreaks.com/topic/22058-phpmysql-issue/#findComment-98707
Share on other sites

That is what the '*' does. If you only wanted to select 'id' and 'name', your query would look like this:

[CODE]SELECT id, name FROM table WHERE status = 1[/CODE]

So if you want to pull all columns, use *. The 'WHERE' clause lets you specify certain information about your results.
Link to comment
https://forums.phpfreaks.com/topic/22058-phpmysql-issue/#findComment-98709
Share on other sites

esahp,

There's nothing wrong with [b]SELECT * FROM table WHERE 1[/b] What you've read elsewhere was correct.

In fact, your original query only had one thing syntactically wrong with it, it had the additional WHERE in there.  When providing a second clause, just use the AND or OR.

[b]SELECT * FROM table WHERE 1 AND status = 1[/b]

Regards
Huggie
Link to comment
https://forums.phpfreaks.com/topic/22058-phpmysql-issue/#findComment-98785
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.