Page 1 of 1

I have a sorting problem

Posted: Thu Jun 01, 2006 10:08 am
by jpaloyo

Code: Select all

$query1 = mysql_query(select * blah)
$query2 = mysql_query(select * blah)
since $query1 and $query2 are not arrays and are considered resource. Right now they can be sorted but seperately, $query1 results would be sorted and right below it $query2 results would be sorted. How do put the 2 results into 1 so that i could sort them? I cant put them in an array since they are resouce right? any suggestions? sample maybe?

Posted: Thu Jun 01, 2006 10:10 am
by feyd
you can put their results in an array.

If you posted your actual select strings it may be possible to combine them.

Posted: Thu Jun 01, 2006 10:12 am
by RobertGonzalez
Read the result resource into and array and merge the arrays...

Code: Select all

<?php
$sql = "SELECT * FORM table1";
if (!$result = mysql_query($sql))
{
    die("There was an error: " . mysql_error());
}
while ($row = mysql_fetch_array($result))
{
    $array1 = $row;
}

$sql = "SELECT * FORM table2";
if (!$result = mysql_query($sql))
{
    die("There was an error: " . mysql_error());
}
while ($row = mysql_fetch_array($result))
{
    $array2 = $row;
}

$newarray = array_merge($array1, $array2);
?>

Posted: Thu Jun 01, 2006 11:18 am
by jpaloyo
wow, really good reply. Thank you so much.