Chris,
Good solution but I should have mentioned we're running PHP 4.04 and I was
getting an undeclared function with array_search. I tried using array_keys
without luck. Here's as far as I got;
while ($make_row = mysql_fetch_array ($make_result)) {
if (in_array ("No model specified", $make_row)) {
$make_row_keys = array_keys ($make_row, "No model
specified");
reset($make_row);
while (list($key,$value) = each($make_row_keys)) {
$noMake = array_splice( $make_row, $value, 0);
$newResults = array_merge( $make_row, $noMake );
}
} else {
$newResults = array_merge( $make_row, $noMake );
}
To clarify, I have to sort on model, not make. I'm querying the database for
make, model, make_id and model_id.
Thanks for the good solution though, I should have been more specific.
Tom
> From: Christopher William Wesley <[EMAIL PROTECTED]>
> Date: Fri, 19 Oct 2001 10:43:35 -0700 (PDT)
> To: php list <[EMAIL PROTECTED]>
> Cc: Tom Beidler <[EMAIL PROTECTED]>
> Subject: Re: [PHP] how to move one element of an array to the end of the array
>
> Splice the array at the point in your result array where "No make
> specified" is, for one element, then append it back onto the result array.
> Here ...
>
> $noMake = array_splice( $resultArray, array_search( "No make specified",
> $resultArray ), 1); // This should be one line, sorry :)
>
> $newResults = array_merge( $resultArray, $noMake );
> // Two lines total
>
> g.luck,
> ~Chris /"\
> \ / September 11, 2001
> X We Are All New Yorkers
> / \ rm -rf /bin/laden
>
> On Fri, 19 Oct 2001, Tom Beidler wrote:
>
>> I'm running a query that pulls up automotive makes for a given year and
>> orders them alphabetically. One of the options is "no make specified" which
>> I would like to always move to the end of the mysql_fetch_array. So my while
>> loop would pull up
>>
>> AMC
>> Ford
>> Volkswagon
>> No make specified
>>
>> Instead of
>>
>> AMC
>> Ford
>> No make specified
>> Volkswagon
>>
>> After looking over the php site it doesn't look like there is an easy way to
>> do it. Should I take the array, remove the element and then add it to the
>> end?
>>
>> The no make specified unique id in the make database is 1. I could order by
>> id, use array_shift to pop off the first element, sort the array by asort,
>> and then add it on the end using array_push.
>>
>> Is there a better way?
>>
>> Thanks,
>> Tom
>>
>> --
>> 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]