HooLIGUN
/**
* Build SELECT statement
*
* @param array|string $columns The columns (as an array) to select or an expression
* @param array|string $table The table to select from. Either (string) table_name or (array) ( name, alias ) or \IPS\Db\Select object
* @param array|string|NULL $where WHERE clause - see \IPS\Db::compileWhereClause() for details
* @param string|NULL $order ORDER BY clause
* @param array|int $limit Rows to fetch or array( offset, limit )
* @param string|NULL|array $group Column(s) to GROUP BY
* @param array|string|NULL $having HAVING clause (same format as WHERE clause)
* @param int $flags Bitwise flags
* @li \IPS\Db::SELECT_DISTINCT Will use SELECT DISTINCT
* @li \IPS\Db::SELECT_MULTIDIMENSIONAL_JOINS Will return the result as a multidimensional array, with each joined table separately
* @li \IPS\Db::SELECT_FROM_WRITE_SERVER Will send the query to the write server (if read/write separation is enabled)
* @return \IPS\Db\Select
*
*/
public function select( $columns=NULL, $table, $where=NULL, $order=NULL, $limit=NULL, $group=NULL, $having=NULL, $flags=0 )
// Get the select object
$select = \IPS\Db::i()->select( '*', 'some_table', array( 'field=?', 1 ), 'some_column DESC', array( 0, 10 ) );
// Force a specific index to be used for the query
$select = $select->forceIndex( 'some_index' );
// Join another table on
$select = $select->join( 'other_table_name', 'other_table_name.column=some_table.column', 'LEFT' );
// Now, get the number of results returned
$results = count( $select );
// Tell the iterator that keys should be 'column_a' and values should be 'column_b'
$select = $select->setKeyField( 'column_a' )->setValueField( 'column_b' );
// Finally, loop over the results
foreach( $select as $columnA => $columnB )
{
print $columnA . ': ' . $columnB . '<br>';
}