Welcome Guest, Not a member yet? Register   Sign In
Passing array variabel in paging
#1

[eluser]novarli[/eluser]
I have checkbox array named "checkbox[]".
Then i have query

$ids=implode(',',$_POST['checkbox']));
$sql="select .... where in ($ids)";

How to pass this variabel ($ids) on paging?
Thanks for your answer ...
#2

[eluser]Mellkior[/eluser]
Two Examples for Model.

Using Active Record - First Example

$ids = array(1,2,3,4,5,6,7); // Your array

$this->db->select('*');
$this->db->where_in('field', $ids);
$query = $this->db->get('table');

// Query = SELECT * from table WHERE field in (1,2,3,4,5,6,7)

return $query->result();


Using PHP - Second Example

$ids = array(1,2,3,4,5); // Your Array

$sql = 'SELECT * from table WHERE field in (';

for($i =0; $i < count($ids); $i++)
{
if($i == 0)
{
$sql .= $ids[$i];
}
else
{
$sql .= ',' . $ids[$i];
}
}

$sql .= ')';

// SQL = SELECT * from table WHERE field in (1,2,3,4,5)

$query = $this->db->query($sql);
return $query->result();
#3

[eluser]novarli[/eluser]
Not that i mean...

I have form displaying record in database. For example company name. Each records has checkbox named "ids[]". When i click button then displayed the employer of the company that selected on checkbox.
The query is

$ids=implode(’,’,$_POST[‘checkbox’]));
$sql="select * from employees where company in ($ids)";

I using paging for display. My Question is how pass array variabel in paging? For page 1 not problem, but if i click next page how pass these array variabels?




Theme © iAndrew 2016 - Forum software by © MyBB