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

The 'Get Where' Method

The 'Get Where' method is for fetching a single record from a database table. It accepts the following parameters:

  • $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.
  • $id (required) - an integer, representing the 'id' value for the record that you would like to fetch.

What Gets Returned?

WHEN A MATCHING RECORD IS FOUND

When matching record is found, a PHP object will be returned where each object property key represents a column from the target database table, and each object property value represents a value that is assigned to the object key.

WHEN A MATCHING RECORD IS NOT FOUND

If the query fails to find any matching records then the boolean value of false is returned.

Example 1

The syntax below shows the simplest Get Where example possible.  In this example, we pass a record 'id' as an argument and the Model will query the table whose name matches the first segment from the URL.

$result = $this->model->get_where(3);

The code above will produce the following SQL query:

SELECT * FROM tablename where id = 3

Just To Let You Know
In a working example, 'tablename' would be replaced with the first segment from the URL.

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

<?php
class Members extends Trongate {

    function test() {
        $result = $this->model->get_where(3);
        json($result);
    }

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:

screenshot

Example 2

Below is a more advanced example:

$result = $this->model->get_where(88, 'fish');

The code above would produce the following SQL query:

SELECT * FROM fish where id = 88



HELP & SUPPORT

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

 
×