RowCount() = 0 错误 php mysql
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
= 是 PHP 中的赋值运算符。
您基本上是在尝试将 0 分配给 $sth7->rowCount()。
也许你的意思是 $sth7->rowCount() == 0?
另外,你真的不需要 if else if。它可能只是一个 if 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:
rowCount() returns an integer, and any integer except for 0 will cast to true.
尝试使用
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.else
不采用任何逻辑,它仅在关联的 if(以及任何 elseif)不计算为 true 时运行。另外,
=
是一个赋值运算符 - 将其读作“变得等于”==
是一个相等运算符,它测试两个表达式是否相等您可能想要
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"==
is an equality operator, it tests if two expressions are equalYou probably want