PHP/MySQL - order results alphabetically?

~~moi~~

New member
Hi, I'm a complete newbie when it comes to PHP/mySQL but I'm part of a group that has to try to improve a system. We want search results to be able to be sorted alphabetically. Here's the PHP code we have:

function GetItemsBySearch($condition, $keywords) {
global $db, $DB_PREFIX, $debug;

if (!$db->isConnected()) return array();


if (count($keywords) == 0) return array();


$where = "i.iditem = ik.iditem AND i.available='2008' AND (";

$first = true;
foreach ($keywords as $item) {
if (!$first) $where .= " OR ";
$where .= " ik.idkeyword = ".$item;
$first = false;
}
$where .= ")";
if (strlen($condition) != 0) {
$where .= " AND MATCH (name, descrip) AGAINST ('".$condition."' in boolean mode) ORDER BY (i.name)";
}


$result = $db->query("distinct i.barcode, i.name, i.descrip, i.borrowLength, i.access, i.picUrl, i.iditem",
$DB_PREFIX."itemkeywords as ik, ".$DB_PREFIX."item as i ",
$where);

$return = array();
foreach ($result as $item) {
$id = $item[6];
array_pop($item);
array_push($return, new Item($id, $item));
}
return $return;
}


I tried adding in the "order by" bit in the where clause, but it doesn't seem to work. Results are still being printed, just not in alphabetical order. Any help?

Thank you so much!
We were given this code, and none of us have sufficient skills or time to rewrite it.
 
Back
Top