20,397
社区成员




if($enews=='get_playurl'){
$id=(int)$_GET['id'];
$sql="select * from {$dbtbpre}ecms where id='$id'";
$rs=$empire->fetch1($sql);
$titleurl=sys_ReturnBqTitleLink($rs);
echo "
InputMusic('$rs[url]|$rs[id]|$rs[title]|".date('Y-m-d',$r[newstime])."|$rs[username]|$rs[classid]');
";
}
上面代码是只读取单个ID的
显示
XX.php?id=123
如果我要它显示多个ID的结果呢?
比如:xx.php?id=123,125,127
要怎么弄呢?
感谢!!!
可以用where in啊
select * from table where field in (value1, value2, ...);
这个请求 xx.php?id=123,125,127
你得到的id值就是字符串123,125,127 那可以直接用啊
不过这样你就不能 $id=(int)$_GET['id'] 进行强转了
建议你传参名改为ids 然后对这个做一些处理
比如用explode() 把传参按照逗号转成数组 在判断这个数组有多少元素。如果是1个 那就不用where in来查询了 直接intval()处理后进行查询好了
如果是多个可以自己新建一个$queryIds 的这种变量 通过遍历这个数组 对值intval()处理后拼接在变量里面构成查询的ids字符串 进行查询
当然是用循环将取得的ID存到数组,然后依次对数组进行处理
$id1 = "123";
$id2 = "125";
$id3 = "127";
$sid = array($id1, $id2, $id3);
$count = count($sid);
$urls = array();
for ($i = 0; $i < $count; $i++) {
$urls = "xx.php?id=" . $sid[$i];
echo $urls;
}
xx.php?id=123
xx.php?id=125
xx.php?id=127