关于select传递多组参数的查询问题

来源:百度知道 编辑:UC知道 时间:2024/07/02 03:50:12
目前有张表topic,里面的字段有topicid, userid, time, content, type,locale.现在使用select * from topic where userid=? and locale=?进行查询。
问题是现在有很多组userid 与 locale信息,
比如 userid locale
111 en
222 en-us
333 zh-en
444 fr
555 ca
... ...
所以实现时每次都要传递不同组的参数,进行很多次查询,才能把所有的结果取出。而现在想进行一次查询就能把所有组参数对应的结果都取出,或者两次查询也可,要尽量减少查询的次数来取出所有想要的结果,请问如何实现呢?
请数据库高手指点,若效果不错的话我再多送分:)
to haifeng_01:能不能再讲清楚些哈,你给的例子我不是能看很懂,能不能按照上面给的情况写一个例子?
to botool: 那若有50组参数的话你是不是也要写50个sql呢,况且多少组参数也不是保持不变的

可将这些参数放在另一张表中,然后进行联合查询即可。

$DBconn=mysql_connect("主机名","用户名","密码") or die("链接失败");
mysql_select_db("数据库名字",$DBconn);
$sql = "select * from topic where 1 ";
$myresult =mysql_query($sql,$DBconn);
$arrList = array();
if($myresult){
while($row = mysql_fetch_assoc($myresult)){
$arrList[] = $row;
}
}
呵呵 所有的数据都在 $arrList 里了
这里是php连接mysql 其他的也类似
呵呵
希望有用

自己组合成sql语句查询不就行了

select * from topic where userid=111 and locale='en' union
select * from topic where userid=222 and locale='en-us' union
select * from topic where userid=333 and locale='zh-en' union
select * from topic where userid=444 and locale='fr' union
select * from topic where userid=555 and locale='ca'