I have a sorting problem

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
jpaloyo
Forum Newbie
Posts: 12
Joined: Tue May 23, 2006 12:53 pm

I have a sorting problem

Post 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?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

you can put their results in an array.

If you posted your actual select strings it may be possible to combine them.
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post 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);
?>
jpaloyo
Forum Newbie
Posts: 12
Joined: Tue May 23, 2006 12:53 pm

Post by jpaloyo »

wow, really good reply. Thank you so much.
Post Reply