getOne() function
fetches a single row based on WHERE criteria
Parameters - getOne( tablename, where, select, sort )
- SQL table name
- WHERE condition - array, multiple values treated as AND parameters
e.g. WHERE col1 = value1 AND col2 = value2 - SELECT arguments - comma-delimited string, defaults to *
- SORT argument - array, i.e. ORDER BY
// Example 1 Object notation
function someFunction( $tableid ) {
$table = $this->model->db->getOne(
'table',
$where=array('tableid'=>$tableid),
$sel='tableid, threadseq',
$sort=array('threadseq'=>'DESC') );
$threadseq = 1;
if ( $table )
$threadseq = $table->threadseq + 1; // object notation
return $threadseq;
}
// Example 2 Array notation
$tableid = $_GET['tableid'];
$WHERE = array();
$WHERE['tableid'] = $tableid;
$table = $this->model->db->getOne('table', $WHERE, $sel='*', $sort=array('threadseq'=>'ASC') );
if ( $table )
echo($table['threadseq'] + 1); // array notation
else
echo("** Table NOT found **\n");