我的客户端使用PHP版本5.2.0,我有一些完美的代码,但目前使用的是5.4.7。当我的代码在他们的服务器上运行时,我收到一个解析错误。我在网上搜索了另一种编写代码的方法,但我找不到任何东西。如果有人有任何提示会有很大的帮助。
**$count = mysqli_query($con, "SELECT COUNT(*) FROM menuitem")->fetch_row()[0];** //I want to make sure the previous and next button are only displayed exactly to the number of items
//in my database. I have to count those items, and turn that mysqli_query object into data. fetch_row[0] stores them
//in an array, starting at 0, turning it into an integer I can use to count below.
$prev = $start - 3;
if ($prev >= 0) {
echo '<td><a href="?start=' . $prev . '">Previous Items</a></td>';// Set your $start - 3 since our offset is 3, and pass that to a variable.
} //if $start - 3 is still greater than 0, then display the previous button. Logically, that is page 2.
$next = $start + 3;
if ($next < $count) {
echo '<td><a href="?start=' . $next . '">Next Items</a></td>';// Since i used fetch_row[0] I now know how many rows I have. If $start + 3 is less than the $count query
} // than you will have a next button. If that number exceeds the number of rows I have, then no next button.
echo "</tr>";
echo "</table>";
在上面的代码中,...-&gt; fetch_row()[0];是带回错误的部分。 PHP 5.2.0不喜欢它。
答案 0 :(得分:2)
在PHP 5.4之前,您could not dereference arrays returned from function calls。只需:
$count = mysqli_query(...)->fetch_row();
$count = $count[0];