simple but baffling

Started on the old forum in September 2009 · view the original in the archive · old links redirect here

14 replies · 667 views · started 17 years ago · 1 min read

3 participants
nclemale36 Lead · 537 posts #1

a simple sql query below has me baffled .dont take much i know.

its for spincards game in chatroom. its not selecting the correct winner.

i have narrowed it down to this statement.

$rpgd = mysql_query("SELECT id, cards FROM dave_users ORDER by cards DESC LIMIT 1");
 while($rpgds=mysql_fetch_array($rpgd))

appreciate any help ta

nclemale36 Lead · 537 posts #3

the person with highest number of cards .or the biggest number to make it simpler.

its selecting the one with the least i think as someone had 273 or sumat and the person who had 5 won. . ???

crazybrumi Super moderator Principal · 1,064 posts #4

change this

$rpgd = mysql_query("SELECT id, cards FROM dave_users ORDER by cards DESC LIMIT 1");

to this

$rpgd = mysql_query("SELECT id, cards FROM dave_users ORDER by cards ASC LIMIT 1");

Want something coded email me at sales@webnwaphost.com for a prices.

http://flagcounter.com/more/W80q

crazybrumi Super moderator Principal · 1,064 posts #6

what your code was doing was finding it but ordering the output in a decending order hence the desc beign there which means itl output the lowest value first and the greater value last, what i had done was changed this to asc which is asending which outputs the greater value first and then the least last.

Want something coded email me at sales@webnwaphost.com for a prices.

http://flagcounter.com/more/W80q

nclemale36 Lead · 537 posts #7

i had looked at some other statements wasnt sure which on e to use. every script that has got this in is wrong then lol .

syrus Junior · 44 posts #14
$rpgd = mysql_query("SELECT id, MAX(cards) FROM dave_users GROUP BY id LIMIT 1");
 while($rpgds=mysql_fetch_array($rpgd)){ echo $rpgds['MAX(card)'] }
nclemale36 Lead · 537 posts #15

ok found the problem wasnt anything to do with the coding. done some research about sql and the database was wrong

this is wot i used which i got off 2 other scripts

 `cards` varchar(10) NOT NULL,

now it should of been

 `cards` int(10) NOT NULL,

apparently a text value 7 is higher than 123445 but a numeric value is obvious lower in which case it was selecting the wrong winner all the time .

u learn something new everyday lol

Write your reply now; next you create a free account (or sign in) and it is posted right away. Sign in to reply.

Similar topics

Keyboard shortcuts

g f
Go to forums
g h
Go to your feed
g m
Go to messages
r
Reply (in a topic)
/
Search
j
Next post
k
Previous post
?
This list
Ctrl/⌘ + Enter
Send what you are writing
Ctrl/⌘ + B / I
Bold / italic while writing
Esc
Close