我有脚本来显示数据库信息而无需重新加载页面。该脚本工作正常,但问题是我想在这里使用codeigniter的分页类,但由于我在我的控制器中使用了一些原始PHP,我不知道该怎么做。 请您告诉我如何在我的脚本中使用分页类?
提前致谢:)
我的脚本::
内心
<script type="text/javascript">
$(document).ready(function() {
$("select[name='users']").attr("selectedIndex", 1);
$("select[name='users']").change(function() {
var str = $(this).val();
if( str == "" ) {
$("#txtHint").html("");
}
else {
$.get("<?php echo base_url(); ?>test/query/"+ str, function(data) { $("#txtHint").html(data) });
}
}).change();
});
</script>
体内
<form>
<select name="users" >
<option value="">Select a person:</option>
<option value="11080101">Sumon</option>
<option value="11080102">Donno</option>
</select>
</form>
<br />
<div id="txtHint"><b>Person info will be listed here.</b></div>
我的控制器:
function query($id){
$sql="SELECT * FROM attendancein WHERE attendeeid = '$id' ";
$result = mysql_query($sql);
echo "<table border='1'>
<tr>
<th>date</th>
<th>In Time</th>
<th>In Status</th>
<th>Class Start Time</th>
</tr>";
while($row = mysql_fetch_array($result))
{
echo "<tr>";
echo "<td>" . $row['date'] . "</td>";
echo "<td>" . $row['intime'] . "</td>";
echo "<td>" . $row['instatus'] . "</td>";
echo "<td>" . $row['classstarttime'] . "</td>";
echo "</tr>";
}
echo "</table>";
}
我没有模特
function query($id){
$sql="SELECT * FROM attendancein WHERE attendeeid = '$id' ";
$result = mysql_query($sql);
$this->load->library('pagination');
$config['base_url'] = base_url().'test/srijon';
$config['total_rows'] = mysql_num_rows($result);
$config['per_page'] = '20';
$config['num_links'] = 20;
$config['full_tag_open'] = '<div class="pagination" align="center">';
$config['full_tag_close'] = '</div>';
$this->pagination->initialize($config);
$sql="SELECT * FROM attendancein WHERE attendeeid = '$id' LIMIT 20, 5";
$result = mysql_query($sql);
echo "<table border='1'>
<tr>
<th>date</th>
<th>In Time</th>
<th>In Status</th>
<th>Class Start Time</th>
</tr>";
while($row = mysql_fetch_array($result))
{
echo "<tr>";
echo "<td>" . $row['date'] . "</td>";
echo "<td>" . $row['intime'] . "</td>";
echo "<td>" . $row['instatus'] . "</td>";
echo "<td>" . $row['classstarttime'] . "</td>";
echo "</tr>";
}
echo "</table>";
echo "<tr><td>" . $this->pagination->create_links() . "</td></tr>";
}
答案 0 :(得分:0)
好的,但是你可以添加一些代码。
function query($id){
$sql="SELECT * FROM attendancein WHERE attendeeid = '$id' ";
$result = mysql_query($sql);
$items_per_page = 5;
$this->load->library('pagination');
$config['base_url'] = base_url().'test/query/'.$id.'/';
$config['total_rows'] = mysql_num_rows($result);
$config['per_page'] = $items_per_page;
$this->pagination->initialize($config);
$current_page = ($this->uri->segment(4) === FALSE ? 0 : intval($this->uri->segment(4)));
$offset = $items_per_page * ($current_page - 1);
$sql="SELECT * FROM attendancein WHERE attendeeid = '$id' LIMIT '$offset', '$items_per_page'";
$result = mysql_query($sql);
echo "<table border='1'>
<tr>
<th>date</th>
<th>In Time</th>
<th>In Status</th>
<th>Class Start Time</th>
</tr>";
echo "<tr><td>" . $this->pagination->create_links() . "</td></tr>"
while($row = mysql_fetch_array($result))
{
echo "<tr>";
echo "<td>" . $row['date'] . "</td>";
echo "<td>" . $row['intime'] . "</td>";
echo "<td>" . $row['instatus'] . "</td>";
echo "<td>" . $row['classstarttime'] . "</td>";
echo "</tr>";
}
echo "</table>";
}
我自己没有对此进行测试,但我相信它无论如何都会起作用,它会让你很清楚你需要做些什么才能让它发挥作用。 **注意5可以放入变量中以使其更易于维护。