Jump to content

Ranking?


brown2005

Recommended Posts

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.

[b] All Female Male[/b]
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?
Link to comment
Share on other sites

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.
[code]
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);
[/code]
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.