2013-06-05 4 views
1

PHP에서 문제가 있습니다. 모든 데이터를 보여주고 중첩 된 루프에 넣으려고했습니다. 두 번째 루프는 null 만 반환합니다. 내가 뭘 잘못했는지 모르겠다.중첩 된 while 루프가 예상대로 작동하지 않습니다.

<?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

검색어가 작동한다고 가정합니다. 거기에 디버깅을 추가하고 무슨 일이 일어나고 있는지 알아보십시오. mysqli_error ($ con)는 무엇을 출력합니까? – andrewsi

+1

'tables_in_yahooFin'에서 대문자와 소문자가 일치하지 않을 수 있습니까? 두 번째 루프에서는'Tables_in_yahooFin'입니다. BTW, 결과를 '1'로 제한하면 두 번째 루프는 어떻게됩니까? – bpoiss

답변

3

또한 당신은 아마 Tables_in_yahoofin이 두 번째에 사용되는 반면 오타 tables_in_yahooFin가 첫 번째 쿼리에 사용이 루프

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

후이 안 여분 ; 세미콜론있다.

+0

오, 이런, 맞아. 이것은 기침약의 영향을 받아 코딩하지 않도록 가르쳐줍니다. 고마워요! –

+0

이 문제가 해결 되었습니까? – Vector

+0

tables_in_yahoofin이 정확합니다. 저것에 문제 없음. –

관련 문제