开发者

Query With array in mysql

I want to fetch contents o开发者_StackOverflow社区f two separate category and insert them in two different boxes. I have written the query like this:

$query = mysql_query(sprintf("SELECT * FROM ".DB_PREFIX."_links WHERE cat = %d LIMIT %d" , 4, 3));

But can we write 2 or more query in one query? like :"select * from blah where cat = (3, 4, 5)"

EDIT:

Query With array in mysql

Thanks in advance


Update 2

To load your data in a specific div, you can store the result in an array and later echo it where you want like this:

$result = mysql_query(...........);

$i = 0;
$data = array();

while($row = mysql_fetch_array($result)){
    $data[$i] = $row;
    $i++;
}

HTML:

<!-- For div 1 -->
<div>
  <?php echo $data[0]['fieldName']?>
</div>

<!-- For div 2 -->
<div>
  <?php echo $data[1]['fieldName']?>
</div>

<!-- For div 3 -->
<div>
  <?php echo $data[2]['fieldName']?>
</div>

Update

You can do something like this:

    $result = mysql_query(...........);
    while($row = mysql_fetch_array($result)){
      echo '<div>' . $row['fieldName'] . '</div>'
    }

This way each record will appear in different div.


But can we write 2 or more query in one query? like :"select * from blah where cat = (3, 4, 5)"

You can do so with IN operator:

select * from blah where cat IN (3, 4, 5)

The IN operator allows you to specify multiple values in a WHERE clause.

More Information:

  • http://www.w3schools.com/sql/sql_in.asp


just use the IN statement of SQL

SELECT * FROM _links WHERE cat IN (3,4,5)
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜