Last active
April 12, 2020 04:33
-
-
Save locvfx/fc944cb0732a75f5b731da9e66226571 to your computer and use it in GitHub Desktop.
Codeigniter DB Query
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
$results = array(); | |
$table_name = ''; | |
$sql = ""; | |
$query = $this->db->query($sql); | |
$results = $query->result_array(); |
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
$total_rows = 1000; | |
$table_name = HOMEPAGE_DATA_TABLE; | |
$query = $this->db->query('SELECT * FROM `'.HOMEPAGE_DATA_TABLE.'` WHERE `availability_instock` = 1 ORDER BY RAND() LIMIT '.NUMBER_OF_RANDOM_PRODUCTS); | |
$data['product']['random_products'] = $query->result_array(); |
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
$table_name = ''; | |
$results = array(); | |
$limit = 1; | |
$sql = "SELECT * | |
FROM $table_name AS r1 JOIN | |
(SELECT CEIL(RAND() * | |
(SELECT MAX(id) | |
FROM $table_name)) AS id) | |
AS r2 | |
WHERE r1.id >= r2.id | |
ORDER BY r1.id ASC | |
LIMIT $limit;"; | |
$query = $this->db->query($sql); | |
$results = $query->result_array(); |
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
$sql = 'SELECT `image` | |
FROM `bf_products_inventory` | |
WHERE `id` BETWEEN '.$start_id.' AND '.$end_id; | |
$query = $this->db->query($sql); | |
$records = $query->result_array(); |
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
$CI =& get_instance(); | |
$query = $CI->db->query($sql); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment