Trongate Docs
switch to dark modeswitch to dark mode
The 'Get Where Custom' Method

The 'Get Where Custom' Method

The 'Get Where Custom' method is for fetching rows of data from a database table.  It accepts the following parameters:

  • $column (required) - the name of the table column referred to when results are fetched.
  • $value (required) - the value that should be matched against the target table column.
  • $operator (optional) - the comparison operator that will be used to fetch records.  By default this is set to the equals symbol ('=').
  • $order_by (optional) - the name of the table column by which results should be ordered.  In instances where you'd like your results to be displayed in descending order, add the characters ' desc' onto your order by argument.  By default, the Model will order results by 'id'.
  • $target_table (optional) - the name of the database table to be queried.  By default, the Model will assume the target table to be equal to the value on the first URL segment.
  • $limit (optional) - the maximum number of results that you would like to return.  By default, the Model will assume no limit.
  • $offset (optional) - the number of rows to skip before fetching results.  

Just To Let You Know
The starting point for a database results set is always assumed to have an offset of 0.

What Gets Returned?


If matching records are found then a PHP array will be returned where each item on the array represents a row from a database table.  Each row, within the array, will be a PHP object.


If the query fails to find any matching records then an empty array will be returned.

Top Tip
Use PHP's inbuilt var_dump() method whenever you need to clarify the variable types from a given results set.

Example 1

The syntax below shows the simplest Get Where Custom example possible.  In this example, we are passing in a column name of 'first_name' and a value of 'Bruce'.

$rows = $this->model->get_where_custom('first_name', 'Bruce');

The code above will produce the following SQL query:

SELECT * from tablename WHERE first_name = 'Bruce' order by id

Below is an example of a Members.php controller file that contains a test() method.  Here we're invoking a basic 'Get' command and then immediately displaying the results using Trongate's json() method:

class Members extends Trongate {

    function test() {
        $rows = $this->model->get_where_custom('first_name', 'Bruce');

Below shows an example of the kind of output that we can expect to see from the above method, when Debug Mode is switched on:


Example 2

Below is a more advanced example:

$rows = $this->model->get_where_custom('trongate_user_id', 88, '>', 'id desc', 'members', '99', 1);

The code above would produce the following SQL query:

SELECT * FROM members where trongate_user_id > 88 order by id desc LIMIT 1, 99


If you have a question or a comment relating to anything you've see here, please goto the Help Bar.