SitePoint Sponsor

User Tag List

Results 1 to 4 of 4

Thread: Need some help

Hybrid View

  1. #1
    SitePoint Evangelist
    Join Date
    Aug 2000
    Location
    Singapore
    Posts
    411
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Need some help

    I need to know how to query a database and ask how many rows have the same record in a column.

    For example, I would like to check how many people signed up with a person, so I have the column, referred. Since many people will have the same input on that, how do I check the total number of people with the same input?

  2. #2
    Victory shall be mine tubedogg's Avatar
    Join Date
    Mar 2001
    Location
    Medina, OH
    Posts
    440
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Code:
    SELECT count(*) AS referrals FROM table_name WHERE referred='$referrer_name';
    Or if you want to display a list of how many people each user has referred:

    PHP Code:
    $results mysql_query("SELECT count(*) AS referrals FROM table_name GROUP BY referred");
    while (
    $row mysql_fetch_array($results)) {
      echo 
    $row['referred']." referred ".$row['referrals']." people.<br>\n";

    Kevin

  3. #3
    SitePoint Evangelist
    Join Date
    Aug 2000
    Location
    Singapore
    Posts
    411
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    How do I display the result of the count?

  4. #4
    Victory shall be mine tubedogg's Avatar
    Join Date
    Mar 2001
    Location
    Medina, OH
    Posts
    440
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    $result mysql_query("SELECT count(*) AS referrals FROM table_name WHERE referred='$referrer_name'");
    $total mysql_result($result,0,0);
    echo 
    "$total for $referrer_name"
    Kevin


Bookmarks

Posting Permissions

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