如何从php中的数组进行SQL查询?

时间:2018-04-11 08:37:45

标签: php mysql sql arrays

请告诉我怎样才能从数组中进行sql查询呢?

.hidden .myAnimation {
   /* Will reset and prevent your animation
      from running when the element is hidden. */
   animation: none;
}

这是以上代码的输出:

This is my code       
$myString = "Food,FastFood,Chinese";
        $myArray = explode(',', $myString);
        print_r($myArray);

我的问题是如何在php中使用此数组进行SQL查询

Array
(
    [0] => Food
    [1] => FastFood
    [2] => Chinese
)

请帮帮我。

4 个答案:

答案 0 :(得分:0)

试试这个

message.channel.send({
  files: [{
    attachment: 'entire/path/to/file.jpg',
    name: 'file.jpg'
  }]
})
.then(console.log)
.catch(console.error);

答案 1 :(得分:-1)

您可以使用IN-Condition创建SQL语句。查看MySQL的官方文档 - MySQL IN-Condition

修改: 这将是您的新查询:

// you first have to implode your array and add quotes for each array item
$string = "'" . implode("','", $myArray) . "'";
// now you can create your new query
$sql = "Select * from table where FoodCategories IN ($string)";

答案 2 :(得分:-1)

您可以使用in

尝试以下

$data = "'".implode("','",$myString)."'";
sql="Select * from table where FoodCategories in($data)";

答案 3 :(得分:-1)

以简单的方式尝试:)

$myString =array("Food","FastFood","Chinese");
// make them together with ', '
$userStr = implode("', '", $myString );
$query="SELECT * FROM table WHERE FoodCategories in ('$userStr')";