Reputation: 3611
I have this database Database Image and an array of user id
<?php
$users = array('0000000002','0000000003');
// I want to show only the post from these $users only..
// I came up with this query..
mysql_query("SELECT * FROM it_posts WHERE postOwner = '0000000002' OR postOwner = '0000000003'");
// but it will not display each post from the $users
?>
Upvotes: 0
Views: 53
Reputation: 382776
You are missing mysql_fetch_array
or other similar fetching functions. Your code should look like this:
$result = mysql_query("SELECT * FROM it_posts WHERE postOwner = '0000000002' OR postOwner = '0000000003'");
while($row = mysql_fetch_array($result)){
echo $row['field_name'];
}
To get it even shorter, use the IN
clause:
$result = mysql_query("SELECT * FROM it_posts WHERE postOwner IN ('0000000002', '000000003'");
Upvotes: 0
Reputation: 41858
Without seeing the schema for table it_posts there is no way to help.
Try doing this in the mysql console and also do select * from it_posts
and see what you get.
You may find that there are no posts with that user id. It may be that
Also, your column name needs to match what is in the database.
Upvotes: 0
Reputation: 35993
mysql_query
is not intented to display everything. It just generrates a data structure containing all the retrieved items from the database.
Have a look over here:
http://www.tizag.com/mysqlTutorial/mysqlselect.php
http://www.w3schools.com/PHP/php_mysql_select.asp
Upvotes: 1