Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/55.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
如果表show X中没有结果,则使用PHP MySQL_Php_Mysql_Pdo - Fatal编程技术网

如果表show X中没有结果,则使用PHP MySQL

如果表show X中没有结果,则使用PHP MySQL,php,mysql,pdo,Php,Mysql,Pdo,我在我的网站上有一个查询,如果没有结果,我想说点别的,而不是一个空白页 $sth = $conn->prepare("SELECT * FROM directory WHERE user_active != '' AND County = :county"); $sth->execute(array(':county' => $county)); $c = 1; while ($row = $sth->fetch(PDO::FETCH_A

我在我的网站上有一个查询,如果没有结果,我想说点别的,而不是一个空白页

    $sth = $conn->prepare("SELECT * FROM directory WHERE user_active != '' AND County = :county");
    $sth->execute(array(':county' => $county));

    $c = 1;
    while ($row = $sth->fetch(PDO::FETCH_ASSOC)) {
        RETURNED DATA GOES HERE
    $c++;
    }
相关文件:


相关文档:

您正在以
$c
计算结果,因此您可以通过在代码中添加以下内容来检查该值:

if($c == 1) { // Counter is stuck at 1
    echo "No results were found.";
}

您正在用
$c
计算结果,因此您可以通过在代码中添加以下内容来检查其值:

if($c == 1) { // Counter is stuck at 1
    echo "No results were found.";
}
2可能的解决办法, 执行选择计数 执行fetchall检查,然后显示结果

2可能的解决方案, 执行选择计数
执行fetchall检查,然后显示结果

+1。但是你的答案有印刷错误-应该是“用
$c
计算结果”,而不是
$i
@a1ex07非常尖锐!更新:)+1。但是你的答案有印刷错误-应该是“用
$c
计算结果”,而不是
$i
@a1ex07非常尖锐!更新:)