Reputation: 1
The code below will display John, Steve, and Pat from a table in my database. I want it to only display John and Steve.
$result = @mysql_query("SELECT * FROM name");
$line = @mysql_fetch_array($result);
$users = $line[user];
echo "$users";
Upvotes: 0
Views: 146
Reputation: 218837
SELECT * FROM name WHERE [column_name] = 'john' OR [column_name] = 'Steve'
Is that what you're looking for? A few notes:
[column_name]
with the name of the actual column being compared, since that's not specified in your code above.SELECT *
where possible. It's generally better practice to select the actual column names. Slightly less work on the database, doesn't break as easily when schema changes, etc.UPDATE: Correction, MySQL isn't case-sensitive. So #3 above shouldn't be a concern in that environment.
Upvotes: 3
Reputation: 10772
I'm not sure if this is what you want, but you can filter by a list of matching names in the SQL thusly:
SELECT * FROM name WHERE name IN ('John', 'Steve')
This assumes your table is called name
and the column containing the user's name is also called name
.
I have to wonder what you are trying to achieve here, is there some other useful information you are trying to get from the user record? Or should you be limiting the users returned based on some other criteria beyond their name?
Upvotes: 2
Reputation: 38516
For this odd example, you could change your query to:
select * from name where name in ('Steve','John')
or
select * from name where name <> 'Pat'
Upvotes: 2
Reputation: 2293
You need a WHERE clause in your SQL query.
SELECT * FROM name WHERE somecolumn=somevalue;
Upvotes: 2