Custom select
Custom select
Hi,
In join table php , i could see a code that get an array for lable and value for drop down menu. This is as follow
[code]if ( !isset($_POST['action']) ) {
// Get department details
$out['access'] = $db
->select( 'access', 'id as value, name as label' )///select id and name from ALL rows of 'access' table.
->fetchAll();
}
[/code]
I have to restrict the selection with a where condition ,For example -to select id and name from those rows of 'access' table where id<3 not all as given in this example.
What modification I have to do here in this code. Hope @Allen will not ignore my request.
In join table php , i could see a code that get an array for lable and value for drop down menu. This is as follow
[code]if ( !isset($_POST['action']) ) {
// Get department details
$out['access'] = $db
->select( 'access', 'id as value, name as label' )///select id and name from ALL rows of 'access' table.
->fetchAll();
}
[/code]
I have to restrict the selection with a where condition ,For example -to select id and name from those rows of 'access' table where id<3 not all as given in this example.
What modification I have to do here in this code. Hope @Allen will not ignore my request.
This discussion has been closed.
Replies
Allan
Yeah i have seen it, but not working for me.
[code] $where=where( $key = 'id', $value = '3', $op = '=' );
$out['access'] = $db
->select( 'access', 'id as value, name as label',$where )
->fetchAll();[/code]
what is wrong with this?
The third parameter of the `select` method is an array ( http://editor.datatables.net/docs/current/php/class-DataTables.Database.html#_select ). It looks like you just need to change first line to be `$where = array( ... );` .
Allan
I tried lot of combinations to include the third parameter in SELECT method as an array but ended up with json errors.
Hence I used simple php direct solution
if ( !isset($_POST['action']) ) {
$accessList = $db->select( 'access', 'id, name' );
$out['accessList'] = array();
while ( $row = $accessList->fetch() ) {
if($row['id']>=3)///used this condition here to limit the array out put .
{
$out['accessList'][] = array(
"value" => $row['id'],
"label" => $row['name']
);}
}
}
It works well. Thank you
Suppose I want to display the rows in which browser is Firefox(as in example). What is the pre-filtering method I should use in data table.
[code]
$out['dept'] = $db
->select( 'dept', 'id as value, name as label', array('id'=>'3') )
->fetchAll();
[/code]
That should do the job nicely.
> Allen, Can you please tell me how to filter the table, using default parameter, for any particular column.
Use oSearch for the global search and aoSearchCols for columns.
Allan
if ( !isset($_POST['action']) ) {
$accessList = $db->select( 'access', 'id, name,dept_id' );
$out['accessList'] = array();
while ( $row = $accessList->fetch() ) {
if($row['dept_id']==_________________________)///comparing the dept id is derived from table
{
$out['accessList'][] = array(
"id" => $row['id'],
"name" => $row['name']
"dept_name" => _________________________///dept_name is value from joined table
);}
}
}
How can i use Join instance in this case. Is it possible?