|
Posted by Marcin Dobrucki on 03/01/06 13:28
laredotornado@zipmail.com wrote:
>
> Using PHP 4 and MySQL 4, how would I write a function such that it
> takes a valid MySQL query, and a column on which to order the query,
> and return a new query ordered by that column?
>
> $query = formNewQuery($query, $orderByCol);
>
> An assumption you can make is that the query will never have multiple
> columns on which to order -- e.g. ("ORDER BY COL_A, COL_B"), however
> the query could contain the "DESC" keyword -- "ORDER BY COL_A DESC".
require_once ('DB.php'); // PEAR::DB
//.. $db =& initialize connection, etc.
$query = 'SELECT * FROM table ORDER BY ! !';
$param = array('column_name', $order);
// where $order = 'ASC' or 'DESC' or ''
$res =& $db->query($query, $param);
// voilá!
//Marcin
[Back to original message]
|