RowCount() = 0 错误 php mysql

发布于 2024-12-03 13:27:17 字数 518 浏览 1 评论 0原文

echo "<h2 style='margin:0; padding:0;'>Recent Comments</h2>";

            if ($sth7->rowCount()) {
                while($row7 = $sth7->fetch(PDO::FETCH_ASSOC)) {
                echo "<div class='comment'>{$row7['usr']} said";
                }
            }
            else($sth7->rowCount() = 0)                                                          
            echo "User";

Can't use method return value in write context

为什么 rowcount() = 0 逻辑不起作用?

echo "<h2 style='margin:0; padding:0;'>Recent Comments</h2>";

            if ($sth7->rowCount()) {
                while($row7 = $sth7->fetch(PDO::FETCH_ASSOC)) {
                echo "<div class='comment'>{$row7['usr']} said";
                }
            }
            else($sth7->rowCount() = 0)                                                          
            echo "User";

Can't use method return value in write context

Why doesnt that rowcount() = 0 logic work?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

原野 2024-12-10 13:27:17

= 是 PHP 中的赋值运算符。

您基本上是在尝试将 0 分配给 $sth7->rowCount()。

也许你的意思是 $sth7->rowCount() == 0?

另外,你真的不需要 if else if。它可能只是一个 if else:

if($sth7->rowCount()) {

} else {

}

rowCount() 返回一个整数,除 0 之外的任何整数都将转换为 true。

= is the assignment operator in PHP.

You're basically trying to assign 0 to $sth7->rowCount().

Perhaps you mean $sth7->rowCount() == 0?

Also, you really don't need the if else if. It could be just an if else:

if($sth7->rowCount()) {

} else {

}

rowCount() returns an integer, and any integer except for 0 will cast to true.

仲春光 2024-12-10 13:27:17

尝试使用 rowcount() == 0 与 0 进行比较,您的代码 (rowcount() = 0) 尝试分配 0。此外,将常量放在比较时的左侧:(0 == rowcount()) 使此类错误更容易检测。

Try rowcount() == 0 to compare with 0, your code (rowcount() = 0) tries to assign 0. Also, it's may be useful to put constant on the left side while comparing : (0 == rowcount()) to make such errors easier to detect.

橘寄 2024-12-10 13:27:17

else 不采用任何逻辑,它仅在关联的 if(以及任何 elseif)不计算为 true 时运行。

另外, = 是一个赋值运算符 - 将其读作“变得等于”

$var = 1; // Var becomes equal to 1

== 是一个相等运算符,它测试两个表达式是否相等

$var == 1 // Var is equal to 1

您可能想要

else if ($sth7->rowCount() == 0)                                                          
     echo "User";

else doesn't take any logic, it just runs if it's assosciated if (and any elseifs) didn't evaluate true.

Also, = is an assignment operator - read it as "becomes equal to"

$var = 1; // Var becomes equal to 1

== is an equality operator, it tests if two expressions are equal

$var == 1 // Var is equal to 1

You probably want

else if ($sth7->rowCount() == 0)                                                          
     echo "User";
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文