Jump to content


Photo

Ranking?


  • Please log in to reply
3 replies to this topic

#1 brown2005

brown2005
  • Members
  • PipPipPip
  • Advanced Member
  • 943 posts

Posted 18 May 2006 - 12:42 PM

Hi i have a members table with these two fields;

firstname
sex

what i want to do is create a ranking table based on these as below.

All Female Male
1 Paul Rachel Paul
2 Rachel Elizabeth Richard
3 Elizabeth Tina Matthew
[b]

I can create single lists, but I dont know if it can be done in one query...

Any ideas please?

#2 samshel

samshel
  • Members
  • PipPipPip
  • Advanced Member
  • 837 posts

Posted 18 May 2006 - 01:02 PM

Hello,

i think i did not get you properly !

can u please elborate more on your query ?

Cheers,
SamShel
-----------------------------------------------
--: FUTURE IS LINUX :--
-----------------------------------------------

#3 brown2005

brown2005
  • Members
  • PipPipPip
  • Advanced Member
  • 943 posts

Posted 18 May 2006 - 01:05 PM

i want a query that says the following:-

most popular female first name
most popular male first name
most popular first name (either male or female)

#4 shoz

shoz
  • Staff Alumni
  • Advanced Member
  • 600 posts

Posted 18 May 2006 - 01:38 PM

You haven't made it clear how you determine the popularity of an individual, but you can do the sorting in PHP using something similar the code below.

Btw, in your first post you give the impression that you want to have a list showing the females and males in an order based on their rank/popularity. While, in your second post you make it seem as though you only want the list to contain one entry for most popular male and most popular female.
SELECT name, sex FROM table ORDER BY rank DESC
$all = array();
$females = array();
$males = array();
$other = array();
while ($row = mysql_fetch_assoc($result))
{
    $all[] = $row['name'];
    if ($row['sex'] == 'f')
    {
         $females[] = $row['name'];
    }
    elseif ($row['sex'] == 'm')
    {
        $males[] = $row['name'];
    }
    else
    {
        $other[] = $row['name'];
    }
}
print_r($all);
print_r($males);
print_r($females);
print_r($other);





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users