php - 获取数组的字符串

标签 php mysql arrays

我正在使用这个获取数组的结果

$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/

相关文章:

PHP:从文件中读取特定行

php - 在带有 MySql 的 PHP 中插入相同结果之前和之前选择

mysql - 将匹配 'numbers'的相对记录分配给mysql group_concat函数中的每条记录

mySQL 创建外键

javascript - 过滤数组并查找拼接索引

php - 将整个 Smarty 模板包装在 {strip} 标签中有什么问题吗?

php - 如何从 View 的 URL 中获取值并在 Controller 中使用它?

mysql - 数据库设计 - 冗余是否比添加更多关系更好?

php - 如何将php数组插入到mysql表中

jquery - 从字符串数组中删除空字符串 - JQuery