嵌套while循环未按预期工作

时间:2013-06-05 17:15:55

标签: php loops while-loop nested

我在php中遇到问题。我试图显示所有数据,然后将它们放在嵌套循环中。但第二个循环只返回空值。我不知道自己做错了什么。

<?php
ini_set('max_execution_time', 36000); 
$con=mysqli_connect("localhost","root","XXX","YahooFin");
if (mysqli_connect_errno()) {
    echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$result = mysqli_query($con,"show tables from yahooFin where not tables_in_yahooFin = 'nasdaqCompanyList' and not tables_in_yahooFin = 'companylist'");
while($row = mysqli_fetch_array($result)) {
    $result2 = mysqli_query($con, "select * from ".$row['Tables_in_yahoofin']." where entry_date = '2013-06-03'order by entry_date asc limit 1");
    while ($row2 = mysqli_fetch_array($result2));  //<== This line gives me null
    {
        var_dump( $row2);
        echo "<br>";
    }
}
var_dump($row);
mysqli_close($con);
?>

1 个答案:

答案 0 :(得分:3)

有一个额外的;分号,在你的循环之后不应该存在

    while ($row2 = mysqli_fetch_array($result2));  //<== This line gives me null
                                              //^ remove this one

此外,您可能会在第一次查询中使用拼写错误tables_in_yahooFin,而在第二次查询中使用Tables_in_yahoofin

相关问题