如何解决语法错误,意外的T
解析错误:语法错误,第27行的view.php中出现意外的T_IF
我真的没有看到我的代码有任何问题,为什么发生这种情况,请帮助。 我是一名PHP初学者
我的LINE 21是>> if(isset($ _ GET ['page'])&& is_numeric($ _ GET ['page']))
if ($result = $mysqli->query("SELECT * FROM players ORDER BY id"))
{
if ($result->num_rows > 0)
{
$total_result = $result->num_rows;
$total_pages = ceil($total_result / $per_page)
if(isset($_GET['page']) && is_numeric($_GET['page']))
{
$show_page = $_GET['page'];
if ($show_page > 0 && $show_page <= $total_pages)
{
$start = ($show_page - 1) * $per_page;
$end = $start + $per_page;
}
else
{
$start = 0;
$end = $per_page;
}
}
else
{
$start = 0;
$end = $per_page;
}
//display paginations
echo "<p> View pages: ";
for ($i=1; $i < $total_pages; $i++)
{
if (isset($_GET['page']) && $_GET['page'] == $i)
{
echo $i . " ";
}
else
{
echo "<a href='view-pag.php?$i'>" . $i . "</a> | ";
}
}
echo "</p>";
}
else
{
echo "No result to display.";
}
}
else
{
echo "Error: " . $mysqli->error;
}
PHP解析器错误需要一些习惯; 如果它抱怨X行出现意外的“某事”,请首先看X-1行。 在这种情况下,它不会告诉你,你在上一行的末尾忘了一个分号,而是会抱怨if
自带未来。
你会习惯它:)
在之前添加分号:
$total_pages = ceil($total_result / $per_page);
这是问题
$total_result = $result->num_rows;
尝试这个
<?php
if ($result = $mysqli->query("SELECT * FROM players ORDER BY id"))
{
if ($result->num_rows > 0)
{
$total_result = $result->num_rows;
$total_pages = ceil($total_result / $per_page);
if(isset($_GET['page']) && is_numeric($_GET['page']))
{
$show_page = $_GET['page'];
if ($show_page > 0 && $show_page <= $total_pages)
{
$start = ($show_page - 1) * $per_page;
$end = $start + $per_page;
}
else
{
$start = 0;
$end = $per_page;
}
}
else
{
$start = 0;
$end = $per_page;
}
//display paginations
echo "<p> View pages: ";
for ($i=1; $i < $total_pages; $i++)
{
if (isset($_GET['page']) && $_GET['page'] == $i)
{
echo $i . " ";
}
else
{
echo "<a href='view-pag.php?$i'>" . $i . "</a> | ";
}
}
echo "</p>";
}
else
{
echo "No result to display.";
}
}
else
{
echo "Error: " . $mysqli->error;
}
?>
链接地址: http://www.djcxy.com/p/69543.html