Frage

I have had problems with this for quite some time now! I have "Ref" in the database that shows which users have being referred and "varvade_antal" shows how many I have recruited. I want to get out all users that have recruited more than 0 for a given date, as long is my code like this:

<?php

    $sql = "SELECT * FROM users WHERE date >= '2013-03-01' AND date < '2013-04-29' + INTERVAL 1 DAY";
    $result = mysql_query($sql) or die(mysql_error());

    while($row = mysql_fetch_array($result)){


    if($row['ref'] == '0') {

    } else {

    $sd = "SELECT * FROM users WHERE id = '{$row['ref']}'";
    $df = mysql_query($sd) or die(mysql_error());

    while($dfs = mysql_fetch_array($df)){


        echo "{$dfs['firstname']}: {$dfs['varvade_antal']} st<br>"; 

   }}}
?>

Now it gets out how many instance I have recruited but it shows duplicates of it, something like this:

Johan have recruited 6 person Johan have recruited 6 person Johan have recruited 6 person Johan have recruited 6 person Johan have recruited 6 person Johan have recruited 6 person

So, when you have recruited 6 people it also print out 6 times! But it should not be so. Help Me?

War es hilfreich?

Lösung

Use this query with DISTINCT

$sql = "SELECT DISTINCT * FROM users WHERE date >= '2013-03-01' AND date < '2013-04-29' + INTERVAL 1 DAY";
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top