I want my query as:
$conditions = array(
'ManageTrackby.trackby_num NOT LIKE' => '%n/a%',
'Balancesheet.subscriber_id' => $_SESSION['Auth']['User']['subscriber_id'],
'Balancesheet.show_id' => $this->Session->read('openshowid'),
'OR' => array('Balancesheet.season_id' => $season_id, 'Balancesheet.season_id is null'),
'OR' => array('Balancesheet.episode_id'=> $episode_id, 'Balancesheet.episode_id is null')
);
which skips last OR option here and giving below result:
Array
(
[ManageTrackby.trackby_num NOT LIKE] => %n/a%
[Balancesheet.subscriber_id] => 105
[Balancesheet.show_id] => 56
[OR] => Array
(
[Balancesheet.episode_id] => 86
[0] => Balancesheet.episode_id is null
)
)
Here, it misses SEASON_ID from the condition, any idea why?
Please guide me !
Try this. If you want all the first conditions, plus an or of the second conditions, then you will want the OR within the AND array. For complex finds, look up the info on this page http://book.cakephp.org/2.0/en/models/retrieving-your-data.html
$conditions = array(
'AND' => array(
'ManageTrackby.trackby_num NOT LIKE' => '%n/a%',
'Balancesheet.subscriber_id' => $_SESSION['Auth']['User']['subscriber_id'],
'Balancesheet.show_id' => $this->Session->read('openshowid')
)
'OR' => array(
array('Balancesheet.season_id' => $season_id, 'Balancesheet.season_id is null'),
array('Balancesheet.episode_id'=> $episode_id, 'Balancesheet.episode_id is null')
)
)
Your array is setting the OR element twice. Put the two OR statements in their own individual array:
$conditions = array(
'ManageTrackby.trackby_num NOT LIKE' => '%n/a%',
'Balancesheet.subscriber_id' => $_SESSION['Auth']['User']['subscriber_id'],
'Balancesheet.show_id' => $this->Session->read('openshowid'),
array('OR' => array('Balancesheet.season_id' => $season_id, 'Balancesheet.season_id is null')),
array('OR' => array('Balancesheet.episode_id'=> $episode_id, 'Balancesheet.episode_id is null'))
);
Related
How can I insert array data to mysql using code igniter ??
I tried example from CI documentation like this
$data = array(
'id_kls' => 'id_kls',
'fk__id_kls' => 'fk__id_kls',
'id_reg_pd' => 'id_reg_pd',
'nm_pd' => 'nm_pd',
'asal_data' => 'asal_data',
'nilai_angka' => 'nilai_angka',
'nilai_huruf' => 'nilai_huruf',
'nilai_indeks' => 'nilai_indeks',
);
$this->db->insert('master_nilai', $data);
// Executes: REPLACE INTO mytable (title, name, date) VALUES ('My title', 'My name', 'My date')
But not working ..
I have array data like this
Array
(
[error_code] => 0
[error_desc] =>
[result] => Array
(
[0] => Array
(
[id_kls] => f77294f7-2a5a-4876-860b-824d227d5b19
[fk__id_kls] => 02
[id_reg_pd] => 001be76b-4e58-4cea-96cf-fee2d8e0abdc
[nm_pd] => SUYATNO
[asal_data] => 9
[nilai_angka] =>
[nilai_huruf] => B
[nilai_indeks] => 3.00
)
Make sure you've enable config/autoload.php/$autoload['libraries'] = array('database');
and config/database.php/your hostname,username,dbname!
I have multiple array to insert into database but i don't fix the field name because can select format table data and insert into database but can check field name with $id_template.
This my format table(example)
So i want to know how can i get data from multiple array to insert into database
This my code in controller
$column = $this->m_rate_template->get_column($id_template);
$colum_detail = implode(",", $column);
$column_cut = explode(",", $colum_detail); //example data get format is Array ( [0] => min [1] => max)
foreach ($column_cut as $key => $val){
$a = $this->input->post($column_cut[$key]);
foreach ($a as $key1 => $val1){
echo $val1;
$child_data = array(
'id' => $this->m_rate_template->generate_id_in_template($template_name),
'id_rate' => $id_rate,
$column_cut[$key] => $val1
);
$this->m_rate_template->insert_rate($child_data, $template_name);
}
}
My data it show like this
Array ( [id] => 4ae665037e [id_rate] => 7f881e02bb [min] => 1 )
Array ( [id] => bc3e60157f [id_rate] => 7f881e02bb [min] => 2 )
Array ( [id] => 082de3ad82 [id_rate] => 7f881e02bb [max] => 1 )
Array ( [id] => ee135ecd8a [id_rate] => 7f881e02bb [max] => 2 )
actually, data should be like this
Array ( [id] => 4ae665037e [id_rate] => 7f881e02bb [min] => 1 [max] => 2)
Array ( [id] => 082de3ad82 [id_rate] => 7f881e02bb [max] => 1 [max] => 2)
Update
$array = array(
[0] => array(
'min' => '2500',
'max' => '5000'
),
[1] => array(
'min' => '5001',
'max' => '7000'
)
)
You can use batch insert to insert multiple
$this->db->insert_batch();
first parameter is table name and second is array of arrays(records)
if you have want to insert multiple record in table then you can also use codeigniter inbuilt insert_batch function without make query in loop.
so i thing your execution will be fast.
you have want to array in below format.
$array = array(
[0] => array(
'column 1' => 'value 1',
'column 2' => 'value 1'
),
[1] => array(
'column 1' => 'value 2',
'column 2' => 'value 2'
)
)
$this->db->insert_batch('tbl_name',$array)
so please make your code and generate your array as above in loop and simply pass your array in insert_batch function.
I am Working on Elastic Search for My current Project. I need a filter for users based on their industries. please look at my code once. and mySql query as follows
SELECT U.* FROM `users` `U`
JOIN `user_industries` `UI` ON `UI`.`user_id`=`U`.`id`
WHERE `UI`.`industry_id` IN('1','3','5');
$query = array("from" => $start,
"size" => $recordslimit,
"sort" => array(array('id' => 'desc')),
"query" => array(
"filtered" => array(
"query" => array("match_all" => array()),
"filter" => array(
"bool" => array(
'must' => array(array('term' => array('user_type' => 'v')),
array('term' => array('status' => 'a')),
array('term' => array('industries.id' => 1))
),
'must_not' => array(
array('term' => array('subscription_type' => 'n'))
)
))
)));
I passed one Industry Value. how can i pass multiple values of industries
Great start !! You can achieve what you want by using a terms filter instead of a term one and specifying the values 1, 3, 5 in an array():
...
array('terms' => array('industries.id' => array(1, 3, 5)))
...
I need to build WP_Query that will return data from database where both conditions are fulfilled, because of that I'm using AND as relation but returned data are different than I expected. To make it more clear I will post WP_Query arguments here.
Array(
[post_type] => Array
(
[0] => event
)
[post_status] => publish
[paged] => 1
[posts_per_page] => 1000
[tax_query] => Array
(
[relation] => AND
[1] => Array
(
[taxonomy] => event_dates
[field] => slug
[terms] => Array
(
[0] => thursday
[1] => exhibitions
)
)
)
)
With this arguments I thought that I'll get events with type exibition AND are on Thursday.
Thanks in advance for help.
The AND is on the wrong level. The WP_Query arguments should look like something like this:
...
'tax_query' => array(
array(
'taxonomy' => 'event_dates',
'field' => 'slug',
'terms' => array('thursday', 'exhibitions'),
'operator' => 'AND'
)
)
...
Is the following join structure correctly formatted to work with a CakePHP find? This doesn't seem to be working when I use it along with conditions and my gut tells me that the structure is off. I'm new to joins, so any help is appreciated.
'joins' => array(
(int) 0 => array(
'table' => 'cheeses_milk_sources',
'alias' => 'CheesesMilkSource',
'type' => 'INNER',
'conditions' => array(
(int) 0 => 'Cheese.id = CheesesMilkSource.cheese_id'
)
),
(int) 1 => array(
'table' => 'milk_sources',
'alias' => 'MilkSource',
'type' => 'INNER',
'conditions' => array(
(int) 0 => 'CheesesMilkSource.milk_source_id = MilkSource.id',
'CheesesMilkSource.milk_source_id' => '1'
)
)
),
'conditions' => array(
'AND' => array(
(int) 0 => array(
'Cheese.cheese_producer_id' => (int) 35
),
(int) 1 => array(
'Cheese.active' => (int) 1
)
)
),
The confusing part is
'conditions' => array(
(int) 0 => 'CheesesMilkSource.milk_source_id = MilkSource.id',
'CheesesMilkSource.milk_source_id' => '1'
)
You are mixing an array element without a key with one with a key equal to CheesesMilkSource.milk_source_id.
if you need to specify two conditions on the join, do it like
'conditions' => array(
'CheesesMilkSource.milk_source_id = MilkSource.id AND CheesesMilkSource.milk_source_id = 1'
)
perhaps the next snippet will equally work, but I'm not sure and can't test it at the moment - let me know if it does with a comment.
'conditions' => array(
'CheesesMilkSource.milk_source_id = MilkSource.id',
'CheesesMilkSource.milk_source_id = 1'
)
But since you're joining the tables, maybe you should put CheesesMilkSource.milk_source_id = 1 in the general conditions of the find:
'conditions' => array(
'Cheese.cheese_producer_id' => 35,
'Cheese.active' => 1,
'CheesesMilkSource.milk_source_id' => 1,
)
Notice you don't need to specify AND as this is the default way of joining conditions.