我正在尝试使用我的SQL数据库(使用最新的MAMP)实现Zebra Pagination,并收到“未选择数据库”错误。我认为问题出在我如何与Zebra建立联系,而没有大量的运气调试。代码:
<?php
$servername = "localhost";
$username = "user";
$password = "password";
$dbname = "database";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
// how many records should be displayed on a page?
$records_per_page = 10;
// include the pagination class
require 'Zebra_Pagination.php';
// instantiate the pagination object
$pagination = new Zebra_Pagination();
$MySQL = "SELECT SQL_CALC_FOUND_ROWS Id
FROM table
LIMIT
' . (($pagination->get_page() - 1) * $records_per_page) . ', ' . $records_per_page . '
";
$result = $conn->query($MySQL);
// if query could not be executed
if (!($result = @mysql_query($MySQL))) {
// stop execution and display error message
die(mysql_error());
}
// fetch the total number of records in the table
$rows = mysql_fetch_assoc(mysql_query('SELECT FOUND_ROWS() AS rows'));
// pass the total number of records to the pagination class
$pagination->records($rows['rows']);
// records per page
$pagination->records_per_page($records_per_page);
?>
<table class="Id" border="1">
<tr><th>Id</th></tr>
<?php $index = 0?>
<?php while ($row = mysql_fetch_assoc($result)):?>
<tr<?php echo $index++ % 2 ? ' class="even"' : ''?>>
<td><?php echo $row['Id']?></td>
</tr>
<?php endwhile?>
</table>
<?php
// render the pagination links
$pagination->render();
$conn->close();
?>
我猜这里只是一个愚蠢的初学者的错误。任何/所有帮助将不胜感激!
对于PHP和第一个Stack问题来说相对较新,因此对我方面的任何错误提前致歉。我正在尝试使用我的SQL数据库(使用最新的MAMP)实现Zebra分页,并获得...