I need to using multiple mysql where: Example mysql_query("SELECT FROM USER where username='%John%' AND username='%Other%'"); PHP: How to
Hi, think, how 1 record can have two different username values? Try two seperate queries: [URL="http://www.php.net/mysql_query"][COLOR=#990000]mysql_query[/COLOR][/URL][LEFT][COLOR=#009900][FONT=monospace]([/FONT][/COLOR][COLOR=#0000FF][FONT=monospace]"SELECT * FROM user [/FONT][/COLOR][COLOR=#0000FF][FONT=monospace]WHERE[/FONT][/COLOR][COLOR=#0000FF][FONT=monospace] username='%John%'"[/FONT][/COLOR][COLOR=#009900][FONT=monospace])[/FONT][/COLOR][COLOR=#339933][FONT=monospace];[/FONT][/COLOR][/LEFT] Code (markup): [URL="http://www.php.net/mysql_query"][COLOR=#990000]mysql_query[/COLOR][/URL][LEFT][COLOR=#009900][FONT=monospace]([/FONT][/COLOR][COLOR=#0000FF][FONT=monospace]"SELECT * FROM user [/FONT][/COLOR][COLOR=#0000FF][FONT=monospace]WHERE[/FONT][/COLOR][COLOR=#0000FF][FONT=monospace] username='%Other%'"[/FONT][/COLOR][COLOR=#009900][FONT=monospace])[/FONT][/COLOR][COLOR=#339933][FONT=monospace];[/FONT][/COLOR][/LEFT] Code (markup): another problem is '*' Look this: [URL="http://www.php.net/mysql_query"][COLOR=#990000]mysql_query[/COLOR][/URL][LEFT][COLOR=#009900][FONT=monospace]([/FONT][/COLOR][COLOR=#0000FF][FONT=monospace]"SELECT * FROM user WHERE username='%John%'"[/FONT][/COLOR][COLOR=#009900][FONT=monospace])[/FONT][/COLOR][COLOR=#339933][FONT=monospace];[/FONT][/COLOR][/LEFT] Code (markup): That will select all the fields from mysql table. If you want to select only specific fields instead of '*' write something else for example: [URL="http://www.php.net/mysql_query"][COLOR=#990000]mysql_query[/COLOR][/URL][LEFT][COLOR=#009900][FONT=monospace]([/FONT][/COLOR][COLOR=#0000FF][FONT=monospace]"SELECT username FROM user [/FONT][/COLOR][COLOR=#0000FF][FONT=monospace]WHERE[/FONT][/COLOR][COLOR=#0000FF][FONT=monospace] username='%John%'"[/FONT][/COLOR][COLOR=#009900][FONT=monospace])[/FONT][/COLOR][COLOR=#339933][FONT=monospace];[/FONT][/COLOR][/LEFT] Code (markup): another examples can be found here: http://www.tuxradar.com/practicalphp/9/3/13 best regards, s.
Do you mean to use LIKE instead of equals? Either way, use or instead of and. If that doesn't get what you're after, perhaps try explaining yourself a little better.
You can use WHERE only once but with several ANDs Also if you want to join other query LEFT JOIN or RIGHT JOIN may help you
mysql_query("SELECT * FROM USER where username LIKE 'John' AND LIKE 'Other'"); Selects all rows in user, where the username is *john* and *other* mysql_query("SELECT * FROM USER where username LIKE 'John' OR LIKE 'Other'"); Selects all rows in user, where the username is *john* or *other*
MySQL has full-text searching so ideally you'd want to use LIKE 'John%' PHP: . Avoid using wildcard at the start of the search string otherwise it cant use the index for this field. Indexes get pretty large an inefficient for full-text though, so ignore this if you aren't indexing. Although you should if this is just a varchar username field.