Re: [PHP] how to move one element of an array to the end of thearray

2001-10-19 Thread Christopher William Wesley

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]




Re: [PHP] how to move one element of an array to the end of thearray

2001-10-19 Thread Tom Beidler

Trying to use the solution without positive results

First need to clarify, I'm actually trying to order the model. Here's my
original query;

$make_query = SELECT make.make, model.model, application.make_id,
application.model_id FROM application INNER JOIN make ON make.id =
application.make_id INNER JOIN model ON model.id = application.model_id
WHERE application.year_in = $value AND application.year_out = $value AND
application.make_id != 1 ORDER BY make.make, model.model;

here's what I tried to change it too

$make_query = SELECT make.make, model.model, application.make_id,
application.model_id FROM application INNER JOIN make ON make.id =
application.make_id INNER JOIN model ON model.id = application.model_id
WHERE application.year_in = $value AND application.year_out = $value AND
application.make_id != 1 ORDER BY make.make, if(left(model.model,7)='No
model specified','',model.model);

I get the same results with both. If you can, let me know where I strayed.

Also, out of curiosity, is it faster to do it in MySQL rather then PHP?

Thanks,
Tom

 From: Mark Charette [EMAIL PROTECTED]
 Date: Fri, 19 Oct 2001 12:34:24 -0500
 To: Tom Beidler [EMAIL PROTECTED], php list
 [EMAIL PROTECTED]
 Subject: RE: [PHP] how to move one element of an array to the end of the array
 
 if(left(Make,7)='no make','',Make)


-- 
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]