我有一个网址如下:
http://url/app/my.php?my=1,2&limit=2&lastid=0
我的参数长度可以变化,但总是用逗号分隔。我想添加到一个mysql查询中,我试着这样做:
$limit = $_GET['limit'];
$lastid = $_GET['lastid'];
$my = $_GET['my'];
$all_news = $con->prepare("SELECT news.id, news.title, news.url, news.image_url, news.date, news.news_text, news.referer_img from news, team, contain WHERE team.id in (?) AND team.id = contain.team_id AND contain.news_id = news.id ORDER BY news.date DESC LIMIT ?, ?");
$all_news->bind_param("iii", $my, $lastid, $limit);
$all_news->execute();
$all_news->bind_result($id, $title, $url, $image_url, $date, $news_text, $referer_img);
我已经尝试将它绑定为字符串和int,但te $ my array似乎在查询中不起作用?我是否需要将其爆炸然后内爆$ my数组?或者我做错了什么?
答案 0 :(得分:0)
您可以尝试parse_str()和parse_url()
$url = parse_url('http://url/app/my.php?my=1,2&limit=2&lastid=0', PHP_URL_QUERY);
parse_str($url);
稍后访问$my
$all_news = $con->prepare("SELECT news.id, news.title, news.url, news.image_url, news.date, news.news_text, news.referer_img from news, team, contain WHERE team.id in (?) AND team.id = contain.team_id AND contain.news_id = news.id ORDER BY news.date DESC LIMIT ?, ?");
$all_news->bind_param("iii", $my, $lastid, $limit);
$all_news->execute();
$all_news->bind_result($id, $title, $url, $image_url, $date, $news_text, $referer_img);