Using queried results in a seperate query Order by
Posted: Thu Mar 22, 2012 9:44 am
I am taking results ($result2) that I get from a one query and formatting them in a way to be inserted in another query. This works fine using the code below
doing this above it gives me these result: 21146, 21032, 21123, 21144
then I insert them here and it works great.
that's where my question comes in I would like to order by the results and Value??
My results currently display zip codes in ascending order like this. (21032, 21123, 21144, 21146) low to high
How can I get the query to display results in the results order above. (21146, 21032, 21123, 21144)
My thought was something like this but it breaks when I use it..
any help would be appreciated 
Code: Select all
//take results and customize them for query value insert
while ($row = mysql_fetch_array($result2, MYSQL_ASSOC))
{
$strquery .= " ".$row["zipcode"].", ";
}
//take list and stop the , at end of query insert
$strquery = rtrim($strquery, ', ');
then I insert them here and it works great.
Code: Select all
$query = "select * from Table where ZipCode IN (".$strquery.") order by Value";
My results currently display zip codes in ascending order like this. (21032, 21123, 21144, 21146) low to high
How can I get the query to display results in the results order above. (21146, 21032, 21123, 21144)
My thought was something like this but it breaks when I use it..
Code: Select all
$query = "select * from Table where ZipCode IN (".$strquery.") order by Value, ZipCode [(".$strquery.")]";