0

如果我为一个人创建了至少 1 个团队,我正在努力做到这一点,它将显示团队。如果他们没有团队,它会说没有团队。如果此人至少有 1 个团队,则它有效,但如果此人不在团队中,则不会显示任何内容。我该如何解决?

<?php

                        $sql = mysql_query("SELECT * FROM teams WHERE players LIKE '%$sessiongamt%'") or die("Could not allocate information!");
                                $num = 0;
                                while($row = mysql_fetch_assoc($sql)){
                                    $num = ++$num;
                        $amount1 = mysql_num_rows($sql);
                        $name = $row["name"];
                                    $teamrank = $row["rank"];
                                    $teamlink = $row["link"];
                                    $players = $row["players"];
                        $teamid = $row['id'];

                        if($amount1 < 1){
                          $teams = "No Teams";
                          echo "$amount";
                        }else{
                          $teams = "$name";
                          echo "<a href='$teamlink?id=$teamid'>$teams</a>";
                        }


                      }print "$amount1";
                    ?>
4

2 回答 2

0

查看这段代码的第三行——把它放在你的代码中的同一个地方,而不是你的行。

                        if($amount1 < 1){
                          $teams = "No Teams";
                          echo $teams;
                        }else{
                          $teams = "$name";
                          echo "<a href='$teamlink?id=$teamid'>$teams</a>";
                        }
于 2013-03-25T03:24:32.533 回答
0

将计数放在 while... 循环之外

$sql = mysql_query("SELECT * FROM teams WHERE players LIKE '%$sessiongamt%'") or die("Could not allocate information!");

$amount1 = mysql_num_rows($sql);  //<---- this should fix it

$num = 0;        
while($row = mysql_fetch_assoc($sql)){
    $num = ++$num;

    $name = $row["name"];
    $teamrank = $row["rank"];
    $teamlink = $row["link"];
    $players = $row["players"];

    $teamid = $row['id'];

    $teams = "$name";
    echo "<a href='$teamlink?id=$teamid'>$teams</a>";
}

if($amount1 < 1){
   $teams = "No Teams";
}

print "$amount1";
?>
于 2013-03-25T03:25:05.253 回答