codeigniter get where

To retrieve data from a database table in CodeIgniter using the "where" condition, you can follow these steps:

  1. Load the database library: Before querying the database, you need to load the database library in CodeIgniter. This can be done by adding the following line of code in your controller or model file:
  1. Build the "where" condition: The "where" condition allows you to specify filters to retrieve specific data from the table. You can use the where() method of the CodeIgniter's Query Builder class to build the condition. Here's an example of how you can write a "where" condition:
$this->db->where('column_name', 'value');

Replace 'column_name' with the name of the column you want to filter on, and 'value' with the value you want to match.

  1. Execute the query: After building the "where" condition, you can execute the query using the get() method of the Query Builder class. This method retrieves the data based on the specified condition. Here's an example:
$query = $this->db->get('table_name');

Replace 'table_name' with the name of the table you want to retrieve data from.

  1. Retrieve the results: The query execution returns a result object, which you can use to retrieve the data. You can use the result() method to get an array of objects representing the rows returned by the query. Here's an example:
$results = $query->result();

You can then loop through the $results array to access the individual rows and their columns.

That's it! You have successfully retrieved data from a database table in CodeIgniter using the "where" condition. Remember to adjust the column names, table name, and condition values according to your specific requirements.