为什么我在使用WHERE语句时无法回显mysql查询结果

时间:2017-09-18 12:59:43

标签: php mysql mysqli

我有下一个没有显示结果的代码:

<?php include ("access.php");
$corpustitle = "Korpus Bilingüe Alemany-Català (de)";
$result = mysqli_query($dbiac, "SELECT corpus FROM corpus_info WHERE title = '$corpustitle'") or die(mysqli_error($dbiac));
while($row = mysqli_fetch_array($result)){ 
echo $row['corpus']."<br>";
} ?>

但是如果我从查询中取出WHERE语句,我会得到下一个结果:

$result = mysqli_query($dbiac, "SELECT corpus FROM corpus_info") or die(mysqli_error($dbiac));
  • banctraddeucat_ca
  • banctraddeucat_de
  • banctraddeuspa_de
  • ...等

如果我在phpmyadmin进行原始查询,我会得到我正在寻找的结果:

enter image description here

1 个答案:

答案 0 :(得分:0)

是的,在@ delboy1978uk评论之后我在查询之前添加了这一行,这就产生了不同:

mysqli_set_charset($dbiac, 'utf8');

所以整个代码现在是:

<?php include ("access.php");
$corpustitle = "Korpus Bilingüe Alemany-Català (de)";
mysqli_set_charset($dbiac, 'utf8');
$result = mysqli_query($dbiac, "SELECT corpus FROM corpus_info WHERE title = '$corpustitle'") or die(mysqli_error($dbiac));
while($row = mysqli_fetch_array($result)){ 
echo $row['corpus']."<br>";
} ?>

...谢谢