Last active
December 26, 2018 02:17
-
-
Save locvfx/dae329ca1306e9feb8bde0ebc6cb4d17 to your computer and use it in GitHub Desktop.
Bonfire - Query builder #database #cibonfire #PHP
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$query = $this->MODELNAME_model->as_array()->find_by('id', $seller_id); | |
$insert_data = array(); | |
if ( $query !== FALSE ){//exist | |
$error=$this->MODELNAME_model->update_where('id', $seller_id, $insert_data); | |
if (!$error) { | |
Template::set_message('Query error', 'danger'); | |
Template::message(); | |
} else { | |
Template::set_message('Success', 'success'); | |
Template::message(); | |
} | |
} | |
else {//not exist | |
$error=$this->MODELNAME_model->insert($insert_data); | |
if (!$error) { | |
Template::set_message('Query error', 'danger'); | |
Template::message(); | |
} else { | |
Template::set_message('Success', 'success'); | |
Template::message(); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$tmp = $this->inventory_model->select('id')->as_array()->order_by($id, 'asc')->find_all(); | |
$max = count($tmp); | |
echo $max; | |
//$tmp = $this->inventory_model->select('id')->as_array()->order_by($id, 'asc')->find_all(); | |
//$max = end($tmp); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$wheres = array('id' => $id); | |
$error = $this->MODEL_NAME_model->delete_where('id' => $id); | |
if (!$error) { | |
$flash_message .= 'Query error: '.$data_table.'<br>'; | |
} else { | |
$flash_message .= 'Deleted all features ('.$lazada_id.'). Data Tabe: '.$data_table.'<br>'; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$products = array(); | |
$total_rows = $this->db->count_all_results($table_name); | |
$products = array(); | |
$i = 0; | |
$succeed_records = 1; | |
do { | |
$return = $this->db->get_where($table_name, array('id' => rand(1,$total_rows), | |
'availability_instock' => 1 | |
), | |
1); //limit 1 | |
if($return->num_rows() == 1){ | |
$result = $return->row_array(); | |
array_push($products, $result); | |
$succeed_records++; | |
$i++; | |
} | |
} while ($i < $number_of_items && $succeed_records <= $number_of_items); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$rows = $this->MODELNAME_model->select('*') | |
->where('gender', 'male') | |
->limit(15,0) //limit, offset | |
->as_array() | |
->find_all(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$row = $this->select('*') | |
->where(array('size' => $size, | |
'status' => 'published', | |
)) | |
->limit(1, 0) //limit, offset | |
->order_by('id', 'RANDOM') | |
->as_array() | |
->find_all(); | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$row = $this->MODELNAME_model->find($id); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$update_data = array( | |
'sync_status' => 'success', | |
); | |
$error = $this->MODELNAME_model->update_where('id', $id, $update_data); | |
if ($error === false) { | |
//Failed | |
} else { | |
//success | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment