codeigniter raw query 1

codeigniter raw query

    $sql="Select * from my_table where 1";    
    $query = $this->db->query($SQL);
    return $query->result_array();

Here is what the above code is Doing:
1. It’s creating a variable called $sql and assigning it a value of “Select * from my_table where 1”.
2. It’s creating a variable called $query and assigning it a value of $this->db->query($SQL).
3. It’s returning the value of $query->result_array().

So, what’s the value of $query->result_array()? It’s an array of arrays. Each array in the array is a row from the database. Each array in the array of arrays has a key for each column in the database. So, if you have a table with columns called “id”, “name”, and “age”, then each array in the array of arrays will have keys called “id”, “name”, and “age”. The value of each key will be the value of the column in the database.

So, if you have a table with columns called “id”, “name”, and “age”, and you have two rows in the table, then the value of $query->result_array() will be:

[
[
“id” => 1,
“name” => “John”,
“age” => “25”
],
[
“id” => 2,
“name” => “Jane”,
“age” => “30”
]
]

So, if you want to get the name of the first row, you would do:

$query->result_array()[0][“name”];

If you want to get the name of the second row, you would do:

$query->result_array()[1][“name”];

If you want to get the age of the first row, you would do:

$query->result_array()[0][“age”];

If you want to get the age of the second row, you would do:

$query->result_array()[1][“age”];

If you want to get the id of the first row, you would do:

$query->result_array()[0][“id”];

If you want to get the id of the second row, you would do:

$query->result_array()[1][“id”];

If you want to get the id of the first row, you would do:

$query->result_array()[0][“id”];

If you want to get the id of the second row, you would do:

$query->result_array()[1][“id”];

If you want to get the id of the first row, you would do:

$query->result_array()[0][“id”];

If you want to get the id of the second row, you would do:

$query->result_array()[1][“id”];

If you want to get the id of the first row, you would do:

$query->result_array()[0][“id”];

If you want to get the id of the second row, you would do:

$query->result_array()[1][“id”];

If you want to get the id of the first row, you would do:

$query->result_array()[0][“id”];

If you want to get the id of the second row, you would do:

$query->result_array()[1][“id”];

If you want to get the id of the first row, you would do:

$query

Similar Posts