我正在使用这个获取数组的结果
$arrayResults = $_GET;
$arr = $arrayResults;
然后我用它来获取变量:
foreach ($arr['seller'] as $seller) {
echo $seller;
}
其中输出 value 1 value 2 value 3 但是当我将它放入 MySQL 查询时它不起作用所以我需要将它们放入一个字符串中并且理想情况下有这样的东西 - < strong>“值 1”或“值 2”或“值 3”
这是我正在使用的查询
$sql_select = "SELECT * ";
$sql_from = "from feeds,product_categories_map where feeds.seller =".dbstr( $seller )." and feeds.enabled=1 and feeds.stock=1 and feeds.deleted=0 and feeds.best_seller=1 and product_id=product_feed_id and product_feed_id!=1 ";
$sql_orderby = " ORDER BY rand()";
$sql_limit = " LIMIT 20";
$query=$sql_select . $sql_from . $sql_group . $sql_orderby . $sql_limit;
$product_results=dbselect( $query,"dbLinkInt" );
我不确定我哪里出错了。
最佳答案
假设您已经清理了您的输入,您应该以这种方式格式化您的变量
$seller = implode("','", $arrayResults); //this format the array into comma separated string
然后将您的查询更改为:
$sql_from = "from feeds,product_categories_map where feeds.seller IN ('".$seller."') and feeds.enabled=1 and feeds.stock=1 and feeds.deleted=0 and feeds.best_seller=1 and product_id=product_feed_id and product_feed_id!=1 ";
关于php - 获取数组的字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48640046/