Welcome Guest, Not a member yet? Register   Sign In
Pagination Arguments - Help!
#1

[eluser]flatulentdog[/eluser]
Ok, so the pagination class passes the page number as an argument in the URI... But for the first page, it doesn't add the argument, right? But this results in a missing argument error... Which is irritating, it might be easier to consider missing arguments as zeros or false rather than crashing... And since this is setup like this, why the hell would you pass an empty argument? What am I missing here?
#2

[eluser]elvix[/eluser]
grab the current page/offset using $this->uri->segment(n,0);

where n is the segment where the offset lives. note the 0 -- adding this returns a 0 if no value is present. now you can pass the result to your db function, no problem.
#3

[eluser]flatulentdog[/eluser]
Thanks, that works. I'm still curious as to why this workaround is necessary, though.
#4

[eluser]srajibtechno[/eluser]
i am facing problem in CI pagination class...

here is my model: test_model.php

class Test_model extends Model
{
function Test_model()
{
parent::Model();
$this->load->database();
session_start();
}

function get_submenu($num,$offset,$id)
{

$this->db->select('*');
$this->db->from('inbook_special_phase_details');
$this->db->where('cat_id', $id);
$query = $this->db->get();
return $query;
}
function get_nrows($num,$offset,$id)
{

$this->db->select('*');
$this->db->from('inbook_special_phase_details');
$this->db->where('cat_id', $id);
$query = $this->db->get();
$n=$query->num_rows();
return $n;
}
}

My Controller....: Group12_Business

class Group12_Business extends Controller
{

function Group12_Business()
{
parent::Controller();
$this->load->helper(array('xml','url'));
$this->load->library('pagination');
$this->load->library('table');
}

function special_menu($id)
{
$a=$this->test_model->get_nrows('3',$this->uri->segment(3),$id);
$_SESSION['cat_id'] = $id;
$this->load->model('test_model');
$config['base_url'] = base_url().'index.php/Group12_Business/special_menu/';
$config['total_rows'] = $a;
$config['per_page'] = '3';
$config['full_tag_open'] = "<div id='pagination'>";
$config['full_tag_close'] = '</div>';

$this->pagination->initialize($config);

$data=array();
$data['results'] = $this->test_model->get_submenu($config['per_page'],$this->uri->segment(3),$id);


$this->load->view('view_special_menu_details',$data);
}
}

View file: 'view_special_menu_details.php

<table width="900" height="380" border="0">
<tr align="left">
<td height="10" colspan="3" align="center"><u><span class="style1">Special Menu Items</span></u></td>
</tr>
&lt;?php
$i=0;
foreach($results->result_array() as $row)
{
$i++;
?&gt;
<tr>
<td width="158"><DIV ID="right_special_menu_list" align="left">&nbsp;&nbsp;&nbsp;&nbsp; <font color="#009900" face="tahoma" size="+1">Menu</font>
<DIV ID="left_sub_menu"> <a href="&lt;?=base_url()?&gt;index.php/Group12_Business/special_menu/1/" style="text-decoration:none;"><font color="#fd7700" face="tahoma" size="2">Today’s Top media</font></a> <br />
<a href="&lt;?=base_url()?&gt;index.php/Group12_Business/special_menu/2/" style="text-decoration:none;"><font color="#fd7700" face="tahoma" size="2">Service</font></a> <br />
<a href="&lt;?=base_url()?&gt;index.php/Group12_Business/special_menu/3/" style="text-decoration:none;"><font color="#fd7700" face="tahoma" size="2">Bussiness</font></a><br />
<br />
</DIV>
</DIV></td>
<td width="82" valign="top" align="center">&nbsp;&nbsp; <a href="&lt;?=base_url()?&gt;assets/images/&lt;? echo $row[" title="&lt;? echo $row["
rel="sexylightbox[galleries]"> <img src="&lt;?=base_url()?&gt;assets/images/&lt;? echo $row[" width="66" height="65" border="0"/></a> <br />
<u>
&lt;?
echo $row["photo_caption"];?&gt;
</u> </td>
<td width="598" valign="top" align="left"><p align="left"> <font color="#fd7700" face="tahoma" size="2"><b>
&lt;?
echo $row["subject"];?&gt;
</b></font> <br />
<br />
&lt;? echo $row["details"];?&gt; <br />
<br />
<br />
<hr />
</p></td>
<td width="44"></td>
</tr>
<tr></tr>
&lt;? } ?&gt;
<tr>

</table>
<div id="pagination" style="position:relative;margin-left:400px;margin-top:10px;">

&lt;?php $this->table->generate($results); ?&gt;

<table border="0">
<tr nowrap="nowrap">
<td> <img src="&lt;?=base_url()?&gt;assets/images/inbooo.gif"/></td>
<td nowrap="nowrap">&lt;?php echo $this->pagination->create_links(); ?&gt;</td>
<td>
<img src="&lt;?=base_url()?&gt;assets/images/k.gif"/></td>
</tr>
</table>
#5

[eluser]srajibtechno[/eluser]
SQL:

CREATE TABLE `inbook_special_phase_category` (
`cat_id` int(11) NOT NULL auto_increment,
`category_name` varchar(20) collate latin1_general_ci NOT NULL,
`category_icon` varchar(150) collate latin1_general_ci NOT NULL,
PRIMARY KEY (`cat_id`),
UNIQUE KEY `cat_id` (`cat_id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci AUTO_INCREMENT=28 ;

INSERT INTO `inbook_special_phase_category` VALUES
(1, 'Media', 'media-icon.png'),
(2, 'Services', 'services.png');

CREATE TABLE `inbook_special_phase_details` (
`content_id` int(11) NOT NULL auto_increment,
`cat_id` int(11) NOT NULL,
`subject` varchar(145) collate latin1_general_ci NOT NULL,
`details` varchar(200) collate latin1_general_ci NOT NULL,
`image_file` varchar(150) collate latin1_general_ci NOT NULL,
`photo_caption` varchar(25) collate latin1_general_ci NOT NULL,
PRIMARY KEY (`content_id`),
UNIQUE KEY `content_id` (`content_id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci AUTO_INCREMENT=42 ;

INSERT INTO `inbook_special_phase_details` VALUES
(41, 1, 'special events 3', 'special events 3 details', 'test.jpg', 'special events 3'),
(1, 2, 'Special Events', 'Specials Events details', 'bachman.jpg', 'bachman'),
(38, 1, 'test2', 'sunset details', '1.jpg', 'sunset'),
(39, 1, 'test3', 'water fall details', '2.jpg', 'water fall'),
(40, 1, 'special events 2', 'special events details', 'test.jpg', 'special events 2');
#6

[eluser]srajibtechno[/eluser]
i want to send cat_id through controller function....

but here is only 2 parameter available in this function

function get_submenu($num, $offset)

that is $num and $offset...but i want to send cat_id with this function....

how can i do this... i am looking forward to hear from you....



thanks

srr
#7

[eluser]flatulentdog[/eluser]
If you read the post here, you can grab URI segments regardless of wethere the controller expects them as arguments or not... which is what is solved by using $this->uri->segment(n,0). Of course, you can always add arguments to your controller.




Theme © iAndrew 2016 - Forum software by © MyBB