It's obviously more effective to do it in MySQL, but you shouldn't have any real processing problems even if you don't find an appropriate solution using MySQL exclusively, because you'd have the two arrays ordered by MySQL, so all you'll have to do would be something like
$myrow1=mysql_fetch_row($result1); while ($myrow2=mysql_fetch_row($result2)) { while (($myrow1) && ($myrow1["Dep_Date"]<$myrow2["Dep_Date"])) { $finalrow[]=$myrow1["Dep_Date"]; $myrow1=mysql_fetch_row($result1); } $finalrow[]=$myrow2; } while ($myrow1=mysql_fetch_row($result1)) { $finalrow[]=$myrow1; } This way you only loop the same number of times as the total number of rows (R1+R2) and perform at most R2 comparisons, which is not bad at all for a sorting function. :-) My sggestion if you really need great optimization on this one would be to address the guys at http://lists.mysql.com (by subscribing to the list). I've seen answers to problems I thought unsolvable through MySQL, so they'll probably find a solution for this one too. Bogdan Yoed wrote: > Hi... I have an interesting problem I don't know which way to solve. So I'll > shoot it out to you guys and see what you might offer. > > I have two databases, say X, and Y: > > CREATE TABLE X( > Id int(11) NOT NULL auto_increment, > Dep_Date date, > Return_Date date, > Cat1_Status varchar(100), > Cat2_Status varchar(100), > Cat3_Status varchar(100), > Cat4_Status varchar(100), > PRIMARY KEY (Id)); > > CREATE TABLE Y( > Id int(11) NOT NULL auto_increment, > Dep_Date date, > Return_Date date, > A_Status varchar(100), > B_Status varchar(100), > C_Status varchar(100), > D_Status varchar(100), > E_Status varchar(100), > PRIMARY KEY (Id)); > > Now what I am trying to do is get it to display on one page one listing in > Chronoligical order based on the Dep_Date from BOTH of these tables. Trying > something simple like > mysql_query("SELECT Id, Dep_Date, Return_DateFROM X,Y WHERE Dep_Date LIKE > '%$SelectDate%' OR Return_Date LIKE '%$SelectDate%' ORDER BY Dep_Date"); > Will give you a ton of errors, and I'm not very fimilar with JOIN and SQL > and how that works. My idea was to create two querys, but the results in > somesort of array, and then order the array by date... I was wondering > though if this is a good efficient way or if you guys have any better > suggestions as to what I should do. > > Thanks for your time and help, > Yoed > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > To contact the list administrators, e-mail: [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]