0

我在其他循环中有一个不工作的循环,这是代码:

    while($row = mysqli_fetch_array($result))
   {
    echo "<tr>";
    echo "<td>" . $row['rowId'] . "</td>";
    echo "<td>" . $row['startDate'] . "</td>";
    echo "<td>" . $row['eventName'] . "</td>";
    echo "<td>" . $row['betName'] . "</td>";
    $string1 = "SELECT * FROM newCell WHERE rowId ='";
    $string2 = $row['rowId']."'";
    $result2 = $string1.$string2;
    echo "<td>" . $result2 . "</td>";

    while($row2 = mysqli_fetch_array($result2))
    {
        echo "<td>" . $row2['odds'] . "</td>";

        echo "<td>" . $row2['outcomeName'] . "</td>";
    }
   echo "</tr>";
   }

当我直接在 BBDD 中查询 $result2 以获取第一个结果时,它显示了三个结果,但代码没有进入第二个循环。为什么?这里有什么错误吗?

4

6 回答 6

0
  while($row = mysqli_fetch_array($result))
   {
    echo "<tr>";
    echo "<td>" . $row['rowId'] . "</td>";
    echo "<td>" . $row['startDate'] . "</td>";
    echo "<td>" . $row['eventName'] . "</td>";
    echo "<td>" . $row['betName'] . "</td>";
    $string1 = "SELECT * FROM newCell WHERE rowId ='";
    $string2 = $row['rowId']."'";
    $result2 = $string1.$string2;
    echo "<td>" . $result2 . "</td>";

    $result2 = mysqli_query($connection, $result2);

    while($row2 = mysqli_fetch_array($result2))
    {
        echo "<td>" . $row2['odds'] . "</td>";

        echo "<td>" . $row2['outcomeName'] . "</td>";
    }
   echo "</tr>";
   }
于 2013-09-26T12:38:04.807 回答
0

利用:

$query = "SELECT ....";
$result2 = mysqli_query($db, $query);

while($row2 = mysqli_fetch_array($result2))
{
        echo "<td>" . $row2['odds'] . "</td>";

        echo "<td>" . $row2['outcomeName'] . "</td>";
}
于 2013-09-26T12:34:49.507 回答
0

我认为 $result2 应该mysqli_query不仅仅是查询的输出。与 MySQL 类似。

可能你应该有这样的东西

$result2 = mysqli_query($result2);
于 2013-09-26T12:35:00.710 回答
0

在阅读本文之前如何防止 PHP 中的 SQL 注入?话题。尝试使用mysql_query()后

于 2013-09-26T12:35:18.337 回答
0

尝试这个

<?php
while($row = mysqli_fetch_array($result))
   {
    echo "<tr>";
    echo "<td>" . $row['rowId'] . "</td>";
    echo "<td>" . $row['startDate'] . "</td>";
    echo "<td>" . $row['eventName'] . "</td>";
    echo "<td>" . $row['betName'] . "</td>";
    $string1 = "SELECT * FROM newCell WHERE rowId ='";
    $string2 = $row['rowId']."'";
    $result2 = $string1.$string2;
    echo "<td>" . $result2 . "</td>";
    $results = mysqli_query($db,$result2);
    while($row2 = mysqli_fetch_array($results))
    {
        echo "<td>" . $row2['odds'] . "</td>";

        echo "<td>" . $row['outcomeName'] . "</td>";
    }
   echo "</tr>";
   }
  ?>
于 2013-09-26T12:35:42.930 回答
0

在获取数据之前,使用 mysqli_query() 函数执行 mysql 查询,然后运行 ​​mysqli_fetch_array()。如果您将结果计为 $count = mysqli_num_rows($query) 并使用 if... else 管理您的代码,那就太好了。

于 2013-09-26T12:43:40.780 回答