Thanks Richard,
But wouldn't "order by z" interfere with my original order by values?
My code is as follows:
$fields1 = " ID, Title, Label, Location, Start, End, Time, ";
$fields1 .= " Description, Organization, Department, Contact, ";
$fields1 .= " Phone, Email, Global, Board, Committee, Status, TBD_Time ";
$command = " SELECT $fields1, TO_DAYS(End) - TO_DAYS(Start) + 1 AS Days
";
$command .= " FROM $tablename ";
$command .= " $WHERETXT ORDER BY $sortby $sortorder ";
I just need to add a new record, but I have to use PHP because the Start and
End
dates for that record must match the current month...
If I could add the record to the Select statement as you suggest that would
be wonderful.
Keith
----- Original Message -----
From: "Richard Lynch" <ceo@xxxxxxxxx>
To: "Keith Spiller" <larentium@xxxxxxxxxxxx>
Cc: <php-general@xxxxxxxxxxxxx>
Sent: Tuesday, October 31, 2006 10:48 AM
Subject: Re: Sorting Multidimensional Array
On Tue, October 31, 2006 11:10 am, Keith Spiller wrote:
RE: Sorting Multidimensional Array
I'm trying to sort a multidimensional array. The data was taken from
a mysql query:
$myrow = mysql_fetch_row($result) {
query[] = $myrow;
}
The purpose is to retrieve the table data and manually add a record,
then sort ASC by the startdate which is the forth field...
Something like:
$test = array_multisort($query, $key = '$query[4]');
Any help would be greatly appreciated. Thanks,
Don't do that. :-)
For starters, sorting in PHP is MUCH less efficient than in a DB.
Secondly, getting multi-dimensional (sic) arrays in PHP to sort like
you want generates a ton of traffic here, so it must be hard. :-)
You can do somethig like this:
(SELECT x, y, z FROM real_data
UNION
SELECT 'manually', 'inserted', 'data' as z
)
ORDER BY z
And achieve MUCH better results with far less headache.
If 'z' is indexed in real_data, add another ORDER BY z right before
the UNION -- That will probably make it very fast/easy for the DB to
splice in your manually-inserted 'z' value.
--
Some people have a "gift" link here.
Know what I want?
I want you to buy a CD from some starving artist.
http://cdbaby.com/browse/from/lynch
Yeah, I get a buck. So?
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php