【发布时间】:2018-10-03 00:50:00
【问题描述】:
我试图在表格中放置一个分页。 我在一个名为 Login 的类中有这个函数,它回显了表的一部分:
public function getCodes()
{
// if database connection opened
if ($this->databaseConnection()) {
$query_codes = $this->db_connection->prepare('SELECT i.id, i.code, i.active, p.enterprise, (SELECT count(*) FROM internal) AS total FROM internal AS i LEFT JOIN pusers AS p ON i.user_id = p.user_id');
$query_codes->execute();
// get result row (as an object)
//$result_row = $query_products->fetchObject();
while ($result_row = $query_codes->fetchObject()){
$this->totalPages = $result_row->total;
echo'<tr>'; // printing table row
echo '<td>'.$result_row->code.'</td><td>'.$result_row->active.'</td><td>'.$result_row->enterprise.'</td>
<td>
<form method="post" action="codes">
<input type="hidden" name="id" value='.$result_row->id.'>
<button type="submit" id="register-submit-btn" class="button" name="delete_code" onclick="return confirm(\'Quieres borrar el Código?\')">Borrar</button>
<button type="submit" id="register-submit-btn" class="button" name="activate_code" onclick="return confirm(\'Quieres activar el Código?\')">Activar</button>
</form>
</td>'; // we are looping all data to be printed till last row in the table
echo'</tr>'; // closing table row
}
} else {
return false;
}
}
在另一个文件中我这样称呼它:
<div class="table-style">
<table class="table-list">
<tbody><tr>
<th>Código</th>
<th>Activo</th>
<th>Empresa</th>
<th>Acciones</th>
</tr>
<?php $login->getCodes();?>
</tbody></table>
</div>
问题是如何将其转换为在表格中进行分页?
【问题讨论】:
标签: php mysql pagination