I have a query and i want to show the result in order by field
$sqlse .= "SELECT ".$tableColumn. " FROM ".$table." WHERE ".$where." AND ".$table2.".account_id IN (353,176,9) OR NOT IN".$table2.".account_id IN (353,176,9) ORDER BY FIELD(account_id,353,176,9)";
I want to show the results in order
account_id Name
353 sandy
176 Abhi
9 jill
42 prahsnt
435 jack
but it show the result in order
42 prashant
435 jack
353 sandy
176 abhi
9 jill
because it returns 0 if it can't find the value in the list you pass to the FIELD
funcion
try this:
... ORDER BY FIELD(account_id, 9 , 176, 353) DESC
"SELECT ".$tableColumn. " FROM ".$table." WHERE ".$where." AND
".$table2.".account_id IN (353,176,9)".
"UNION ALL".
"SELECT ".$tableColumn. " FROM ".$table." WHERE ".$where." AND
".$table2.".account_id NOT IN (353,176,9)";