mysql problem with random value

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Bora
Forum Newbie
Posts: 4
Joined: Sun Jan 04, 2004 12:27 pm

mysql problem with random value

Post by Bora »

I have problem with get random id and total amount of rows for each kat.

Code: Select all

ID | KAT
 1    1
 2    3
 3    3 
 4    2
 5    2
 6    2
 7    1
 8    1

Code: Select all

SELECT COUNT(id), id, kat
FROM `table` GROUP BY kat
ORDER BY RAND()
GROUP always join rows selecting first rows. So it each time looks like this

Code: Select all

kat, COUNT(id), id
 1  , 3        , 1 
 2  , 3        , 4 
 3  , 2        , 2
How to solve this problem ?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

odd.. I don't remember having that sort of problem.. are you trying to access the data via numeric indices? You could switch to the named indices.. :?
Bora
Forum Newbie
Posts: 4
Joined: Sun Jan 04, 2004 12:27 pm

Post by Bora »

could u show how this table looks ??? I try but when i'm using GROUP BY id is still fitst value
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

when I make a duplicate of that table strcture and query, I get the expected results, with 'COUNT( id )' as the first column..
Post Reply