Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.