duanboxue3422 2015-04-21 09:02
浏览 59
已采纳

将数组从url传递到mySQL查询

I have an url which is looking like following:

http://url/app/my.php?my=1,2&limit=2&lastid=0

Where the my paramater length can vary, but is always seperated by a comma. This i would like to add into a mysql query, which i've tried to do like following:

$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);

I've tried both binding it as a string and int, but te $my array does not seem to work in the query? do i need to explode it and then implode the $my array? or what am i doing wrong?

  • 写回答

1条回答 默认 最新

  • dpn517111 2015-04-21 09:06
    关注

    You can try to parse_str() and parse_url()

    $url = parse_url('http://url/app/my.php?my=1,2&limit=2&lastid=0', PHP_URL_QUERY);
    parse_str($url);
    

    And access the $my later on

    $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);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 微信会员卡接入微信支付商户号收款
  • ¥15 如何获取烟草零售终端数据
  • ¥15 数学建模招标中位数问题
  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向
  • ¥15 如何用python向钉钉机器人发送可以放大的图片?