开发者

MYSQL Query: show only the post from these $users only

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

?>


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


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'"); 


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜