User Guide | Querying SQL Results

A guide to returning data from SQL queries returned by flexi cart functions.

Querying SQL Results

Customising SQL Statements Index | Defining Custom SQL Statements | Building Custom SQL Queries | Misc. Admin Functions

Returning Query Results by Chaining CodeIgniter Functions

flexi cart provides many SQL SELECT query functions that return query objects using CodeIgniters Active Record class.

To return data from the query objects, CodeIgniters query result functions ('result()', 'row()' etc.) can be directly chained to the returned object.

Examples

Note: These examples use the 'get_db_table_data()' function as an example SQL SELECT query function.

// Example #1: Chaining CodeIgniters 'result()' function.

$this->flexi_cart_admin->get_db_table_data('example_table')->result();
// Example #2: Chaining CodeIgniters 'row_array()' function.

$this->flexi_cart_admin->get_db_table_data('example_table')->row_array();
// Example #3: Returning the query object without applying a result function.

$this->flexi_cart_admin->get_db_table_data('example_table');

Returning Query Results using an Alternative Syntax

To offer an alternative and slightly tidier syntax, flexi cart allows you to automatically return the query data type that you want by defining so via the functions actual name.

This method still uses CodeIgniters query result functions, but simply does the chaining for you, returning the exact same data.


Alternative Syntax

Note: The following 'xxx' values represent the name of the flexi cart function that is being chained.

CodeIgniter Function Alternative Syntax Description
xxx->result() xxx_result() Returns a query result as an array of objects, or an empty array on failure.
xxx->row() xxx_row() Returns a single result row as an object. If the query has more than one row, it returns only the first row.
xxx->result_array() xxx_array() Returns a query result as a pure array, or an empty array when no result is produced.
xxx->row_array() xxx_row_array() Returns a single result row as an array. If the query has more than one row, it returns only the first row.
xxx->num_rows() xxx_num_rows() Returns the number of rows returned by a query.
Notes

Using the alternative syntax can be used on virtually all SQL SELECT functions that are available in the admin library.

Functions that are compatible are defined via each functions details described in this user guide.

Examples

Note: These examples use the 'get_db_table_data()' function as an example SQL SELECT query function.

// Example #1: Returning CodeIgniters 'result()' query data using alternative syntax.

$this->flexi_cart_admin->get_db_table_data_result('example_table');
// Example #2: Returning CodeIgniters 'row()' query data using alternative syntax.

$this->flexi_cart_admin->get_db_table_data_row('example_table');
// Example #3: Returning CodeIgniters 'result()' query data using alternative syntax.

$this->flexi_cart_admin->get_db_table_data_array('example_table');
// Example #4: Returning CodeIgniters 'row_array()' query data using alternative syntax.

$this->flexi_cart_admin->get_db_table_data_row_array('example_table');
// Example #5: Returning CodeIgniters 'num_rows()' query data using alternative syntax.

$this->flexi_cart_admin->get_db_table_data_num_rows('example_table');
// Example #6: Returning the query object without applying a result function.

$this->flexi_cart_admin->get_db_table_data('example_table');