Php 如何根据codeigniter中的recno移动到下一个条目
我有四个按钮first、last、previous和next按钮如果用户单击first按钮,则必须显示recno的min no,如果用户单击next,则必须显示minof next no条目。我的问题是我没有收到任何错误,我有四个按钮。(first、next、prev、last)所有按钮都不起作用..请帮助我根据记录转到下一个条目..提前感谢。。。。 这是我的控制器代码:Php 如何根据codeigniter中的recno移动到下一个条目,php,codeigniter,paging,Php,Codeigniter,Paging,我有四个按钮first、last、previous和next按钮如果用户单击first按钮,则必须显示recno的min no,如果用户单击next,则必须显示minof next no条目。我的问题是我没有收到任何错误,我有四个按钮。(first、next、prev、last)所有按钮都不起作用..请帮助我根据记录转到下一个条目..提前感谢。。。。 这是我的控制器代码: $first = $this->db->query('SELECT MIN(recno) AS `fir
$first = $this->db->query('SELECT MIN(recno) AS `first` FROM `daybook` ORDER BY recno DESC LIMIT 1')->row_array();
$firstID = $this->db->query("SELECT * FROM `daybook` where recno='$first[first]' ORDER BY recno ASC")->result_array();
//$firstID = $firstIDQuery->result_array();
$last = $this->db->query('SELECT MAX(recno) AS `last` FROM `daybook` ORDER BY recno DESC LIMIT 1')->row_array();
$lastID = $this->db->query("SELECT * FROM `daybook` where recno='$last[last]' ORDER BY recno")->result_array();
//$lastID = $lastIDQuery->result_array();
$id = 1;
if(!empty($id)){
$result = $this->db->query("SELECT * FROM daybook WHERE recno = $id")->result_array();
}
//$result = $resultQuery->result_array();
$data['currentID'] = $id;
$data['firstID'] = $first;
$data['lastID'] = $last;
$data['result'] = $result;
$this->load->view('BookKeeping/DayBookEntry', $data, FALSE);
这是我的查看页面:
<ul class='pagination'>
<a href='<?php echo base_url().'/BookKeeping/daybook/'.$firstID; ?>' class='button'>First</a><br>
<?php
if($currentID != $firstID){
foreach ($result as $next_key => $next_value) {
if($currentID == $next_value['recno']){
$nextID = $result[$next_key]++;
}
}}
?>
<a href='<?php echo base_url().'/BookKeeping/daybook/'.$nextID['recno']; ?>' class='button'>Next</a><br>
<?php
if($currentID != $lastID){
foreach ($result as $prev_key => $prev_value) {
if($currentID == $prev_value['recno']){
$prevID = $result[$prev_key]--;
}
}}
?>
<a href='<?php echo base_url().'/BookKeeping/daybook/'.$prevID['recno']; ?>' class='button'>Previous</a><br>
<a href='<?php echo base_url().'/BookKeeping/daybook/'.$lastID; ?>' class='button'>Last</a><br>
</ul>
它在first、last、next、prev中打印正确的值。我使用print_r(exp)检查了它,我的问题是如何在link(href links)中显示它。您在所有内容上都错误地使用单引号,而不是在适当的情况下使用单引号和双引号的组合,这会影响链接的正确创建 而不是
<a href='<?php echo base_url().'/BookKeeping/daybook/'.$nextID['recno']; ?>' class='button'>Next</a><br>
试一试
工作答案
控制器代码:
$first = $this->db->query('SELECT MIN(recno) AS `first` FROM `daybook` ORDER BY recno DESC LIMIT 1')->row_array();
$firstID = $this->db->query("SELECT * FROM `daybook` where recno='$first[first]' ORDER BY recno ASC")->result_array();
//$firstID = $firstIDQuery->result_array();
$last = $this->db->query('SELECT MAX(recno) AS `last` FROM `daybook` ORDER BY recno DESC LIMIT 1')->row_array();
$lastID = $this->db->query("SELECT * FROM `daybook` where recno='$last[last]' ORDER BY recno")->result_array();
//$lastID = $lastIDQuery->result_array();
//$id = 1;
if(!empty($id)){
$result = $this->db->query("SELECT * FROM daybook WHERE recno = $id")->row_array();
}else{
$result = "";
}
$allData = $this->db->query("SELECT * FROM daybook ORDER BY recno ASC")->result_array();
//$result = $resultQuery->result_array();
if(!empty($id)){
$data['currentID'] = $id;
}else {
$data['currentID'] = $first['first'];
}
$data['firstID'] = $first;
$data['lastID'] = $last;
$data['result'] = $result;
$data['allData'] = $allData;
查看页面:
<a href='<?php echo base_url().'/BookKeeping/daybook/'.$firstID['first']; ?>' class='button'><i class="icon-first">First</i></a><br><br>
<?php
if($currentID != $lastID['last']){
foreach ($allData as $next_key => $next_value) {
//echo $next_key+1;
//echo '<pre>';print_r($next_value);exit();
if($currentID == $next_value['recno']){
$nextID = $allData[$next_key+1];
}
}
$anchorTagNext = base_url().'/BookKeeping/daybook/'.$nextID['recno'];
}else {
$anchorTagNext = '#';
}
?>
<a href='<?php echo $anchorTagNext; ?>' class='button'><i class="icon-next">Next</i></a><br><br>
<?php
if($currentID != $firstID['first']){
foreach ($allData as $prev_key => $prev_value) {
//echo '<pre>';print_r($prev_value);exit();
if($currentID == $prev_value['recno']){
//echo $allData[$prev_key-1]['recno'];exit();
$prevId = $allData[$prev_key-1];
}
}
$anchorTagPrevious = base_url().'/BookKeeping/daybook/'.$prevId['recno'];
} else {
$anchorTagPrevious = '#';
}
?>
<a href='<?php echo $anchorTagPrevious; ?>' class='button'><i class="icon-previous">Previous</i></a><br><br>
<a href='<?php echo base_url().'/BookKeeping/daybook/'.$lastID['last']; ?>' class='button'><i class="icon-last">Last</i></a>
</ul>
你不工作是什么意思?什么都没发生?行为不是你所期望的?按钮没有被渲染?按钮被渲染,但href
部分丢失、损坏、错误?当我单击第一个按钮时,它必须移动到min recno,但在我的情况下,它并没有移动到最小输入,所有按钮都是相同的。我有点担心,事实上,您对所有内容都只使用单引号,而没有正确使用单引号和双引号。这很可能会妨碍链接的正确形成。
<a href='<?php echo base_url().'/BookKeeping/daybook/'.$firstID['first']; ?>' class='button'><i class="icon-first">First</i></a><br><br>
<?php
if($currentID != $lastID['last']){
foreach ($allData as $next_key => $next_value) {
//echo $next_key+1;
//echo '<pre>';print_r($next_value);exit();
if($currentID == $next_value['recno']){
$nextID = $allData[$next_key+1];
}
}
$anchorTagNext = base_url().'/BookKeeping/daybook/'.$nextID['recno'];
}else {
$anchorTagNext = '#';
}
?>
<a href='<?php echo $anchorTagNext; ?>' class='button'><i class="icon-next">Next</i></a><br><br>
<?php
if($currentID != $firstID['first']){
foreach ($allData as $prev_key => $prev_value) {
//echo '<pre>';print_r($prev_value);exit();
if($currentID == $prev_value['recno']){
//echo $allData[$prev_key-1]['recno'];exit();
$prevId = $allData[$prev_key-1];
}
}
$anchorTagPrevious = base_url().'/BookKeeping/daybook/'.$prevId['recno'];
} else {
$anchorTagPrevious = '#';
}
?>
<a href='<?php echo $anchorTagPrevious; ?>' class='button'><i class="icon-previous">Previous</i></a><br><br>
<a href='<?php echo base_url().'/BookKeeping/daybook/'.$lastID['last']; ?>' class='button'><i class="icon-last">Last</i></a>
</ul>