Results 1 to 2 of 2

Thread: MySQL Numbers

  1. #1
    Join Date
    Apr 2005
    Posts
    4,614
    Tokens
    1,290

    Latest Awards:

    Default MySQL Numbers

    I have a database where users send in a name like 'Dave' and I want to display the top 5 names voted for. I know I could use mysql_num_rows to get the number of times a name has been voted for, but how would I display the top 5 names using mysql_num_rows?

    +rep to helpers

  2. #2
    Join Date
    Apr 2005
    Posts
    4,614
    Tokens
    1,290

    Latest Awards:

    Default

    right, ive sorta figured it but it displays it like this

    Red has been voted for 2 times
    Red has been voted for 2 times
    Blue has been voted for 1 times
    the code is

    PHP Code:
    $query "SELECT * FROM `colours` ";
    $result mysql_query($query) or die (mysql_error()."<br />Couldn't execute query: $query"); 
    $numrows mysql_num_rows($result);
     
    echo 
    '';
    while(
    $row mysql_fetch_array($result)) {
     
    $color $row["color"];
     
    $query2 "SELECT * FROM `colours` WHERE `color` = '$color'";
    $result2 mysql_query($query2) or die (mysql_error()."<br />Couldn't execute query: $query"); 
    $numrows2 mysql_num_rows($result2);
     
     
    echo 
    "$color has been voted for $numrows2 times<br>";
     

    any help? thanks
    Last edited by Robbie; 03-02-2008 at 09:57 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •