0

我有问题让这个工作。我也尝试过彼此内部的查询,但它不起作用。有人知道为什么吗?

$ligan  = mysql_query("SELECT leagueId FROM league WHERE leagueName='$leagueName'");
$laget  = mysql_query("SELECT teamid FROM team WHERE leagueId='$ligan'");
$result = mysql_query("SELECT * FROM player WHERE teamId='laget'"); 

这是打印的地方...

            <?php
            if(mysql_num_rows($result) == 0){
            echo $result;
            }
            else{
                while($row = mysql_fetch_array($result)){
                  echo "<tr>";
                  echo "<td>" . $row['playerName'] . "</td>";
                  echo "<td>" . $row['birthday'] . "</td>";
                  echo "<td>" . $row['weight'] . "</td>";
                  echo "<td>" . $row['height'] . "</td>";
                  echo "<td>" . $row['madeGoals'] . "</td>";

                  echo "</tr>";


                  }
            }
                mysql_close($db); ?>

我遇到了这个问题:mysql_num_rows() 期望参数 1 是资源,布尔值在

我相信 ligan 提供一个价值,而 laget 提供很多。

你能帮我吗?

4

4 回答 4

2

我不知道为什么这些答案不建议您使用JOIN,我认为它更容易工作,并且创建它的原因是为了解决像您这样的问题。

mysql_query是的,正如所有答案所指出的那样,您有一个 PHP 错误。

我的建议是,了解JOIN

我认为您的代码将是这样的:

SELECT * FROM player
INNER JOIN team on team.leagueId = league.id
INNER JOIN league on league.name = '$leagueName'

试试JOIN,我保证你的代码看起来会更好,你的生活会更轻松 = )

于 2013-04-14T18:03:48.683 回答
1

mysql_query() 返回结果集,而不是结果本身。您必须从结果集中获取结果。

在此示例中,我检查结果集以确保在访问其中的第一个结果之前有结果。

$resultset = mysql_query("SELECT leagueId from league WHERE leagueName='$leagueName'");

if( mysql_num_rows( $resultset ) > 0 ){
  $row = mysql_fetch_assoc( $resultset );
  // access the ID via $row['leagueId']
}
于 2013-04-14T17:42:58.063 回答
0
$result = mysql_query(
  "SELECT * FROM player WHERE teamId IN (
    SELECT teamid from team WHERE leagueId IN (
      SELECT leagueId from league WHERE leagueName='$leagueName'
    )
  )"
);
于 2013-04-14T17:41:59.903 回答
0

你不获取变量的变量,你只是执行查询。

$result = mysql_query("SELECT leagueId from league WHERE leagueName='$leagueName'");    
$row = mysql_fetch_row($result);    
$result = mysql_query("SELECT teamid from team WHERE leagueId='$row[0]'");    
$row = mysql_fetch_row($result);    
$result = mysql_query("SELECT * FROM player WHERE teamId='$row[0]'");

while ($row = mysql_fetch_assoc($result)) {
    echo $row["name"];
    echo $row["surname"];        
}
于 2013-04-14T17:42:21.473 回答