我做了一些愚蠢的T_T
我在我的代码中重写了用于分页的脚本,我试图制作我用Google搜索的所有脚本以使其有效。但不小心我覆盖原始脚本并保存。实际上我已经为我的备份重命名了文件,但是我将从一些教程中获得的脚本粘贴到我的php-editor上的错误窗口中。糟透了,我完全是傻瓜。现在我遇到了这个脚本的麻烦,我已经尝试了一切,也从这个论坛中获取了示例脚本,但没有结果。错误是:(它在我覆盖连接代码之前有效)
Warning: mysqli_query() expects parameter 2 to be string, object given in C:\xampp\htdocs\acikiwir\index.php on line 8
Warning: mysqli_fetch_array() expects parameter 1 to be mysqli_result, null given in C:\xampp\htdocs\acikiwir\index.php on line 19
Title | Author | Publisher | Category | Link
我的脚本:
<?php
$con = mysqli_connect("localhost", "root", "", "db_books");
$query = mysqli_query($con,'SELECT b.*, title, author_name, url_flipbook, p.publisher_name, ct.cat_name FROM flipbook AS b
LEFT JOIN mst_publisherflip AS p ON b.publisher_id=p.publisher_id
LEFT JOIN mst_catflip AS ct ON b.cat_id=ct.cat_id
ORDER BY flip_id');
$result = mysqli_query($con, $query);
echo "<table border='1'>
<tr>
<th>Title</th>
<th>Author</th>
<th>Publisher</th>
<th>Category</th>
<th>Link</th>
</tr>";
while($row = mysqli_fetch_array($result))
{
echo "<tr>";
echo "<td>" . $row['title'] . "</td>";
echo "<td>" . $row['author_name'] . "</td>";
echo "<td>" . $row['publisher_name'] . "</td>";
echo "<td>" . $row['cat_name'] . "</td>";
echo "<td>" . $row['url_flipbook'] . "</td>";
echo "</tr>";
}
echo "</table>";
mysqli_close($con);
?>
在该脚本中我只更改了连接代码,原始文件被删除/覆盖了一些包含代码,因此我必须再次将连接文件与此主脚本分开。我试图从这个论坛编写代码连接,但仍然会出错。非常感谢你们,如果你们能帮助我解决这些问题......谢谢你们。谢谢你。
答案 0 :(得分:3)
您正在运行mysqli_query
两次。这是主要问题。
像这样改写..
$result = mysqli_query($con,'SELECT b.*, title, author_name, url_flipbook, p.publisher_name, ct.cat_name FROM flipbook AS b
LEFT JOIN mst_publisherflip AS p ON b.publisher_id=p.publisher_id
LEFT JOIN mst_catflip AS ct ON b.cat_id=ct.cat_id
ORDER BY flip_id') or die(mysqli_error($con));