I'm storing user preferences for sort order in a table:
$queryHistory = "SELECT orderby,ascdesc FROM user WHERE UserID= ".$id;
$resultHistory = doQuery($connection, $queryHistory);
$numHistory = mysql_num_rows($resultHistory);
if ($numHistory > 0) {
while($rowHistory = fetchRow($resultHistory, $queryHistory)) {
$orderBy = getResult($rowHistory, $resultHistory, 1);
$sortBy = getResult($rowHistory, $resultHistory, 2);
}
}
And constructing a query based on that which looks like:
$otherQuery = "SELECT *
FROM user
WHERE user.UserID = $id
ORDER BY ".$orderBy." ".$sortBy;
Is it possible to do this with a single query, rather than first reading the preferences then running the actual query?
