RE: [PHP] Ordering a query

2001-09-08 Thread Matthew Loff


You could insert a ternary operation...

($order?$order:defaultfield)

Is the same as:

if($order) 
echo $order;
else
echo defaultfield;

...

$result = mysql_query(SELECT
articles.title,vote.votes,vote.total,articles.date,staff.firstname,artic
les.content,articles.id FROM staff,articles,vote WHERE articles.authorid
= staff.id AND articles.id = vote.item ORDER BY .
($order?$order:defaultfield) . DESC,$db);


-Original Message-
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]] 
Sent: Friday, September 07, 2001 10:05 PM
To: [EMAIL PROTECTED]
Subject: [PHP] Ordering a query


I use the following code to order the results of the query by the
variable $order.

$result = mysql_query(SELECT
articles.title,vote.votes,vote.total,articles.date,staff.firstname,artic
les.content,articles.id FROM staff,articles,vote WHERE articles.authorid
= staff.id AND articles.id = vote.item ORDER BY `$order` DESC,$db);

I assign the variable a value according to my url,
http://www.mysite.com/file.php?order=something

My question is. Is there a way of assigning the $order variable a
default value? Like if they hit http://www.mysite.com/file.php without
the order=something can I tell the script to assign $order a default
value?

Thanks,
Nate


-- 
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] ordering a query

2001-09-07 Thread George Pitcher

It is simply ordering them as type data rather than as type integer. Change
your data type in the db.

George, a newbie
- Original Message -
From: [EMAIL PROTECTED]
To: [EMAIL PROTECTED]
Sent: Friday, September 07, 2001 9:16 AM
Subject: [PHP] ordering a query


Me again :)

I have a query that orders by id#, the problem is I have 17 items and I get
an output like so: 1,10,11,12,13,14,15,16,17,2,3,4,5,6,7,8,9

So it thinks 1 and 10 are the same, and it thinks 11 is less than 2 and so
on and so forth. Remedy please? (I'd rather not rename the items 01, 02, 03,
04, etc.)

Thanks again.

Nate



_
Do You Yahoo!?
Get your free @yahoo.com address at http://mail.yahoo.com


-- 
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] ordering a query

2001-09-07 Thread Tom Carter

Just to expand slightly on this answer...
think back to days at school, you order works as so aardvark, abbey,
accoustic, ie you compare rightmost letters, if they match then compare the
next letter along until you find a difference... this is what your sort is
doing. It doesn't think 1 and 10 are the same, it compares the first digit,
sees they are the same and postitions based on the second digit.

As george correctly says changing the column type to INT will make sure the
RDBMS orders them numerically rather than alphabetically

Tom, a rambler
- Original Message -
From: George Pitcher [EMAIL PROTECTED]
To: [EMAIL PROTECTED]
Cc: [EMAIL PROTECTED]
Sent: Friday, September 07, 2001 9:00 AM
Subject: Re: [PHP] ordering a query


 It is simply ordering them as type data rather than as type integer.
Change
 your data type in the db.

 George, a newbie
 - Original Message -
 From: [EMAIL PROTECTED]
 To: [EMAIL PROTECTED]
 Sent: Friday, September 07, 2001 9:16 AM
 Subject: [PHP] ordering a query


 Me again :)

 I have a query that orders by id#, the problem is I have 17 items and I
get
 an output like so: 1,10,11,12,13,14,15,16,17,2,3,4,5,6,7,8,9

 So it thinks 1 and 10 are the same, and it thinks 11 is less than 2 and so
 on and so forth. Remedy please? (I'd rather not rename the items 01, 02,
03,
 04, etc.)

 Thanks again.

 Nate



 _
 Do You Yahoo!?
 Get your free @yahoo.com address at http://mail.yahoo.com


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