# Data Selection

# where()

Sets the condition of choice.

Parameters:

fields -

value -

Multiple calls are united all the conditions with the 'AND' operator.

# Option 1

Accept the input field and value. The field should be indicated by a sign of comparison. Value will be automatically quoted.

$xcrud->where('catid =', 5);
$xcrud->where('created >', $last_visit);
// or
$xcrud->where('catid =', 5)->where('created >', $last_visit);

# Option 2

Accepts associations are an array of field-value. The field should be indicated by a sign of comparison. Value will be automatically quoted.

$cond = array('catid =' => 5, 'created >' => $last_visit);
$xcrud->where($cond);

Please note:

all the conditions in array will be merged with the operator 'AND'.

# Option 3

Accepts custom line environment, you must specify the name of the table in front of each field, to avoid any conflict in relationships with other tables. You also have to take care of yourself on preparing values.

$xcrud->where("content.catid = 5 AND content.created > '{$last_visit}'");
// or
$xcrud->where("", "content.catid = 5 AND content.created > '{$last_visit}'"); // 1.5 compat.

# Alternative Usage

// using OR glue
$xcrud->where('catid', 5);
$xcrud->or_where('created >', $last_visit);
 
// using IN and NOT IN
$xcrud->where('catid', array('5','7','8'); // `catid` IN ('5','7','8')
$xcrud->where('catid !', array('5','7','8'); // `catid` NOT IN ('5','7','8')

# or_where()

The same as where() method, but multiple calls will be united with operator 'OR'

# no_quotes()

fields ) - The method allows to cancel the automatic shielding values, so you can use the functions in mysql query. Affects on where expressions and pass_var () method. Takes comma-separated fieldnames or array of fieldnames in first parameter.

Parameters:

fields -

$xcrud->no_quotes('created');
$xcrud->pass_var('created','now()');
//or
$xcrud->where('created !=','null');

# relation()

field, target_table,target_id, target_name, where, order_by, multi, concat_separator, tree, depend_field, depend_on ) - binds the current table with a list of the other table. Takes as input the name of the field in the current table, the name of the linked table, the link field, the title field , the selection condition for the linked table (optional).

Parameters:

fields -

$xcrud->relation('catid','categories','cid','category_name',array('published' => 1));
//or
$xcrud->relation('catid','categories','cid','category_name','categories.published = 1');

Since 1.5.4 relation() has additional parameters:

relation ( field, target_table, target_id, target_name, where_array, main_table, multi, concat_separator, tree, depend_field, depend_on )

field - main table relation field, that will be replases; data will be written in this field
target_table - related (target) table, options for dropdown will be get from here
target_id - row id from target table, will be writen into field
target_name - field, that will be displayed as name of dropdown option. This can be array of few fields.
where - (optional) - allows to specify selection items from the target_table, see where(). Default is null.
order_by - (optional) - order by condition (eg. 'username desc'). Default is by target_name.
multi - (optional, boolean) - can change dropdown to multiselect (items will be saved separated by comma). Default is false.
concat_separator - (optional) - take effect only when target_name is array. Default is ' '.
tree - (optional) - array, sets tree rendering of dropdown list. Options: 1. array('primary_key'=>'some_id_field_name','parent_key'=>'some_field_name') - primary and parent key field name, will be created pk tree. 2. array('left_key'=>'some_field_name','level_key'=>'some_field_name') - left key and level field names, will be created nested sets tree.
depend_field - field from current table, options will be extracted based on parent field value ( like country_id column in cities table)
depend_on - field, thats will be parent to current dropdown.

You can use {field_tags} in 'where' parameter to get variable from current row

# fk_relation()

label, field, fk_table, in_fk_field, out_fk_field, rel_tbl, rel_field, rel_name, rel_where, rel_orderby, rel_concat_separator, before, add_data ) - allows to create, manage and display many-to-many connections. The syntax is similar to relation().

Parameters:

fields -

label - Displaing field label (mus be unique, used as alias)
field - connection field from current table
fk_table - connection table
in_fk_field - field, connected with main table
out_fk_field - field, connected with relation table
rel_tbl - relation table
rel_field - connection field from relation table
rel_name - field, that will be displayed as name of dropdown option. This can be array of few fields.
rel_where - (optional) - allows to specify selection items from the target_table, see where(). Default is null.
rel_orderby - (optional) - order by condition (eg. 'username desc'). Default is by rel_name.
rel_concat_separator - (optional) - take effect only when rel_name is array. Default is ' '.
before - (optional) - if selected, field will be inserted before this field (by default - in the end)
add_data (array) - (optional) - additional inserting data

Structure of connections:

table
|- field  --|
            |
            |    fk_table
            |--  |- in_fk_field
                 |- out_fk_field  --|
                                    |
                                    |    rel_table
                                    |--  |- rel_field

# nested_table()

inst_name, connect_field, nested_table, nested_connect_field ) - takes instance name in first parameter, main field in second parameter, nested table in third and connection field from nested table in 4th.

Parameters:

fields -

Nested tables are using for easy editing of related records in other tables, such as the order and the goods in the order (see demo).

You can specify one nested table for each field of your main table. You can set options for nested tables as well as you do for the main table. Method nested_table () creates an instance of a nested table, access to which can be obtained through the field name (specified in the first parameter of the method nested_table ()), only add to it the prefix nested_.

$xcrud->table('orders'); // main table
$products_list = $xcrud->nested_table('products_list','orderNumber','orderdetails','orderNumber'); // nested table
$products_list->unset_add(); // nested table instance access

# search_pattern()

'%', '%' ) - allows to define search pattern for grid search. Method replaces default param ($search_pattern) from configuration.

Parameters:

fields -