我在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);
?>
答案 0 :(得分:3)
有一个额外的;
分号,在你的循环之后不应该存在
while ($row2 = mysqli_fetch_array($result2)); //<== This line gives me null
//^ remove this one
此外,您可能会在第一次查询中使用拼写错误tables_in_yahooFin
,而在第二次查询中使用Tables_in_yahoofin
。