esahp Posted September 26, 2006 Share Posted September 26, 2006 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? Quote Link to comment https://forums.phpfreaks.com/topic/22058-phpmysql-issue/ Share on other sites More sharing options...
livepjam Posted September 26, 2006 Share Posted September 26, 2006 $query = "SELECT * FROM users WHERE 1 AND WHERE `status` = '1'";Do you mean to say this?$query = "SELECT * FROM users WHERE `status` = '1'"; Quote Link to comment https://forums.phpfreaks.com/topic/22058-phpmysql-issue/#findComment-98704 Share on other sites More sharing options...
jeremywesselman Posted September 26, 2006 Share Posted September 26, 2006 Why do you have the 'WHERE 1 AND' there? You need to specify what is equal to '1' which you have done with 'status'. Is there another column you want to pull that equals '1'? Quote Link to comment https://forums.phpfreaks.com/topic/22058-phpmysql-issue/#findComment-98705 Share on other sites More sharing options...
esahp Posted September 26, 2006 Author Share Posted September 26, 2006 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] Quote Link to comment https://forums.phpfreaks.com/topic/22058-phpmysql-issue/#findComment-98707 Share on other sites More sharing options...
livepjam Posted September 26, 2006 Share Posted September 26, 2006 Try this:$query = "SELECT * FROM users WHERE `status` = '1'";You only need to say WHERE once. So if you had more than one argument you would say 'status'='1' and name='Matt' Quote Link to comment https://forums.phpfreaks.com/topic/22058-phpmysql-issue/#findComment-98708 Share on other sites More sharing options...
jeremywesselman Posted September 26, 2006 Share Posted September 26, 2006 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. Quote Link to comment https://forums.phpfreaks.com/topic/22058-phpmysql-issue/#findComment-98709 Share on other sites More sharing options...
esahp Posted September 26, 2006 Author Share Posted September 26, 2006 I see, thanks guys.That line without [b]WHERE 1 AND[/b] also worked, thankyou. Quote Link to comment https://forums.phpfreaks.com/topic/22058-phpmysql-issue/#findComment-98710 Share on other sites More sharing options...
HuggieBear Posted September 26, 2006 Share Posted September 26, 2006 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]RegardsHuggie Quote Link to comment https://forums.phpfreaks.com/topic/22058-phpmysql-issue/#findComment-98785 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.