Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/263.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php MySQL:如何在MySQL的WHERE in子句中使用内爆数组?_Php_Mysql - Fatal编程技术网

Php MySQL:如何在MySQL的WHERE in子句中使用内爆数组?

Php MySQL:如何在MySQL的WHERE in子句中使用内爆数组?,php,mysql,Php,Mysql,当我试图在WHERE in子句中使用内爆数组并显示它时,我遇到了一个问题。数据库中的某些记录中有一个撇号。 示例我的数据库中的数据是测试,测试,测试。下面的代码是我如何内爆要在WHERE in子句中使用的数据 检查以下代码 <?php $arr = array(); $qry = mysqli_query($con,"SELECT sampleTxt FROM Table")or die(mysqli_error($con)); while(list($txt) = mysqli_fet

当我试图在
WHERE in
子句中使用内爆数组并显示它时,我遇到了一个问题。数据库中的某些记录中有一个撇号。 示例我的数据库中的数据是
测试
测试
测试
。下面的代码是我如何内爆要在
WHERE in
子句中使用的数据

检查以下代码

<?php 
$arr = array();
$qry = mysqli_query($con,"SELECT sampleTxt FROM Table")or die(mysqli_error($con));
while(list($txt) = mysqli_fetch_row($qry)){
  //$t = mysqli_real_escape_string($con,$txt);
  $arr[] = '"'.$txt.'"';
  }
$sampl = implode(',',$arr);
?>

然后

<?php
$qry2 = mysqli_query($con,'SELECT sampleTxt2 FROM Table2 WHERE sampleTxt IN ('.$sampl.')')or die(mysqli_error($con));
while(list($txt2) = mysqli_fetch_row($qry2)){
  echo $txt2;
  }
?>


您能否创建一个var\u dump($sampl)并共享输出?显示打印($t)的结果
$t
不是数组。但是如果我要打印
print\r($arr)
,结果是
数组([0]=>“testing”[1]=>“testing”[2]=>“tes't”)
如果我要回显
$sampl
,结果是
“testing”、“test'ing”、“tes't”