Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Old 12-23-2007, 06:29 AM Order By Problem!
evans123's Avatar
Ultra Talker

Posts: 468
Trades: 0
Does order by work with minus numbers because i wanna sort this range.

Points: 3 Goal Difference: 1
Points: 0 Goal Difference: - 1
Points: 3 Goal Difference: 4
Points: 0 Goal Difference: -4

I am sorting my points desc first and then goal difference.
Mysql Query:
PHP Code:
$sql mysql_query("SELECT * FROM `manager__tables` WHERE `league` = '" $league['name'] . "' ORDER BY `goal_difference` DESC, `points` DESC"); 
The range should look like this:

Points: 3 Goal Difference: 4
Points: 3 Goal Difference: 1
Points: 0 Goal Difference: -1
Points: 0 Goal Difference: -4

But it looks like This


Points: 3 Goal Difference: 4
Points: 3 Goal Difference: 1
Points: 0 Goal Difference: -4
Points: 0 Goal Difference: -1
evans123 is offline
Reply With Quote
View Public Profile Visit evans123's homepage!
 
 
Register now for full access!
Old 12-23-2007, 06:45 AM Re: Order By Problem!
evans123's Avatar
Ultra Talker

Posts: 468
Trades: 0
Also When Trying to rank the numbers 1 - 20 its goes like this:

1
11
12
13
14
15
16
17
18
19
20
2
3
4
5
6
7
8
9
evans123 is offline
Reply With Quote
View Public Profile Visit evans123's homepage!
 
Old 12-23-2007, 06:48 AM Re: Order By Problem!
maxxximus's Avatar
Extreme Talker

Posts: 219
Name: Rob
Location: UK
Trades: 0
Goal difference and points are always going to be numbers.

Your quoting them so they become strings - remove your quotes and you should be one your way.
maxxximus is offline
Reply With Quote
View Public Profile
 
Old 12-23-2007, 08:05 AM Re: Order By Problem!
dansgalaxy's Avatar
Defies a Status

Posts: 6,521
Name: Dan
Location: Swindon
Trades: 0
Quote:
Originally Posted by evans123 View Post
Also When Trying to rank the numbers 1 - 20 its goes like this:

1
11
12
13
14
15
16
17
18
19
20
2
3
4
5
6
7
8
9

I think this is basically because MYSQL count funny lol.

you can probably do it with php or a workarround.
__________________
Discounted Web Hosting With XDnet!
>> Get 25% of hosting~ Promo: Webmaster-talk <<

Please login or register to view this content. Registration is FREE
dansgalaxy is offline
Reply With Quote
View Public Profile Visit dansgalaxy's homepage!
 
Old 12-23-2007, 08:14 AM Re: Order By Problem!
chrishirst's Avatar
Missing! presumed drunk.

Posts: 42,384
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
Quote:
I think this is basically because MYSQL count funny lol.
Only if the numbers are actually strings (as maxxximus pointed out)
__________________
Chris. ->>
Please login or register to view this content. Registration is FREE
<<-

A foolish consistency is the hobgoblin of little minds
Thought for today:- Is SEO the only industry where all the cowboys are Indians?
chrishirst is online now
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 12-24-2007, 12:03 AM Re: Order By Problem!
J0ker's Avatar
Skilled Talker

Posts: 61
Trades: 0
I am having a similar problem. I am trying to grab the contents of the field bid out of the table and order desc but it doesn't seem to work. Here is my code for the query:

Quote:
"SELECT * FROM Links ORDER BY bid DESC LIMIT 10"
There are 3 things and the order comes out:
43
32
138

If I change it to ASC it outcomes:
138
32
43

The only thing I can think of is that before I add to the DB I round it from 138.00 to just 138, but that still doesnt really make sense. Anyone?
__________________

Please login or register to view this content. Registration is FREE
- Free Gaming Forum/Arcade

Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE
J0ker is offline
Reply With Quote
View Public Profile
 
Old 12-24-2007, 12:22 AM Re: Order By Problem!
joder's Avatar
Flipotron

Posts: 6,442
Name: James
Location: In the ocean.
Trades: 0
Quote:
Originally Posted by J0ker View Post
I am having a similar problem. I am trying to grab the contents of the field bid out of the table and order desc but it doesn't seem to work. Here is my code for the query:



There are 3 things and the order comes out:
43
32
138

If I change it to ASC it outcomes:
138
32
43

The only thing I can think of is that before I add to the DB I round it from 138.00 to just 138, but that still doesnt really make sense. Anyone?
Your Links field is a string data type such as varchar. Your data type needs to be int or float.
joder is offline
Reply With Quote
View Public Profile
 
Old 12-24-2007, 05:50 AM Re: Order By Problem!
lizciz's Avatar
Super Spam Talker

Posts: 807
Name: Mattias Nordahl
Location: Sweden
Trades: 0
As both maxxximus and joder pointed out, you save your numbers as strings. When comparing strings, lets say 'a' and 'b', which one somes first? 'a', right. When comparing 'aaaaaaaaaa' with 'bbb', which one comes first? Right, 'aaaaaaaaaa'. And so 'azzzzz' comes before 'zaa'.

Now lets compare '40' to '1073'. As a human you understand that 40 is smaller than 1073 and should come first, but since it's a string, and '1' comes before '4', that means '1073' comes before '40'.
lizciz is offline
Reply With Quote
View Public Profile Visit lizciz's homepage!
 
Old 12-24-2007, 06:15 AM Re: Order By Problem!
dansgalaxy's Avatar
Defies a Status

Posts: 6,521
Name: Dan
Location: Swindon
Trades: 0
i know its because of it being a string but can someone tell me a logical reason why the programmers didnt think hey lets tell it how to count if the numbers a string too?
__________________
Discounted Web Hosting With XDnet!
>> Get 25% of hosting~ Promo: Webmaster-talk <<

Please login or register to view this content. Registration is FREE
dansgalaxy is offline
Reply With Quote
View Public Profile Visit dansgalaxy's homepage!
 
Old 12-24-2007, 07:31 AM Re: Order By Problem!
mtishetsky's Avatar
King Spam Talker

Posts: 1,226
Name: Mike
Location: Mataro, Spain
Trades: 0
Number is a number, string is a string. They are used for different purposes. Strings are compared different than numbers. To compare strings as numbers you should cast them to numbers first. If you try to compare strings as strings and receive not what you expected don't blame programmers, in this case the only stupid person is you.
__________________

Please login or register to view this content. Registration is FREE
-
Please login or register to view this content. Registration is FREE
-
Please login or register to view this content. Registration is FREE

And don't forget to give me talkupation!
mtishetsky is offline
Reply With Quote
View Public Profile Visit mtishetsky's homepage!
 
Old 12-24-2007, 07:32 AM Re: Order By Problem!
mtishetsky's Avatar
King Spam Talker

Posts: 1,226
Name: Mike
Location: Mataro, Spain
Trades: 0
Because nobody knows what you really expect to get when you make if ($string == $another_string), that's why type casting was invented.
__________________

Please login or register to view this content. Registration is FREE
-
Please login or register to view this content. Registration is FREE
-
Please login or register to view this content. Registration is FREE

And don't forget to give me talkupation!
mtishetsky is offline
Reply With Quote
View Public Profile Visit mtishetsky's homepage!
 
Old 12-24-2007, 08:40 AM Re: Order By Problem!
Novice Talker

Posts: 4
Trades: 0
i have got same problem, it work now perfectly .(Strings are compared different than numbers.( 1234..) To compare strings as numbers you should cast them to numbers first.)
__________________

Please login or register to view this content. Registration is FREE

Please login or register to view this content. Registration is FREE

Please login or register to view this content. Registration is FREE
freesite is offline
Reply With Quote
View Public Profile Visit freesite's homepage!
 
Old 12-24-2007, 08:54 AM Re: Order By Problem!
dansgalaxy's Avatar
Defies a Status

Posts: 6,521
Name: Dan
Location: Swindon
Trades: 0
Quote:
Originally Posted by mtishetsky View Post
Number is a number, string is a string. They are used for different purposes. Strings are compared different than numbers. To compare strings as numbers you should cast them to numbers first. If you try to compare strings as strings and receive not what you expected don't blame programmers, in this case the only stupid person is you.
Thanks for that i was just wondering why they didnt just make it the same if the string was alll numbers...

so while you have both said it anyone want to tell me and everyone how to convert a string to number?
__________________
Discounted Web Hosting With XDnet!
>> Get 25% of hosting~ Promo: Webmaster-talk <<

Please login or register to view this content. Registration is FREE
dansgalaxy is offline
Reply With Quote
View Public Profile Visit dansgalaxy's homepage!
 
Old 12-24-2007, 01:18 PM Re: Order By Problem!
J0ker's Avatar
Skilled Talker

Posts: 61
Trades: 0
Thank you! This was totally killing me!
__________________

Please login or register to view this content. Registration is FREE
- Free Gaming Forum/Arcade

Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE
J0ker is offline
Reply With Quote
View Public Profile
 
Old 12-24-2007, 02:10 PM Re: Order By Problem!
joder's Avatar
Flipotron

Posts: 6,442
Name: James
Location: In the ocean.
Trades: 0
Quote:
Originally Posted by dansgalaxy View Post
Thanks for that i was just wondering why they didnt just make it the same if the string was alll numbers...

so while you have both said it anyone want to tell me and everyone how to convert a string to number?
http://www.php.net/intval
joder is offline
Reply With Quote
View Public Profile
 
Old 12-24-2007, 02:45 PM Re: Order By Problem!
chrishirst's Avatar
Missing! presumed drunk.

Posts: 42,384
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
and in SQL

... CONVERT('456',unsigned) as converted ...
__________________
Chris. ->>
Please login or register to view this content. Registration is FREE
<<-

A foolish consistency is the hobgoblin of little minds
Thought for today:- Is SEO the only industry where all the cowboys are Indians?
chrishirst is online now
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 12-26-2007, 02:58 AM Re: Order By Problem!
mtishetsky's Avatar
King Spam Talker

Posts: 1,226
Name: Mike
Location: Mataro, Spain
Trades: 0
I usually use (int)$var
__________________

Please login or register to view this content. Registration is FREE
-
Please login or register to view this content. Registration is FREE
-
Please login or register to view this content. Registration is FREE

And don't forget to give me talkupation!
mtishetsky is offline
Reply With Quote
View Public Profile Visit mtishetsky's homepage!
 
Reply     « Reply to Order By Problem!
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.69446 seconds with 12 queries