2012-11-21 2 views
2

나는 현재 mysqli/PDO로 점프하고 있으며, SELECT 루프를 "old"메쏘드에서 mysqli로 변환 중이다.Mysqli "SELECT * FROM"loop

if ($pending_stmt=$mysqli->prepare('SELECT * FROM transactions WHERE status = ?')) { 
    $pending_stmt->bind_param('s', $status); //$status is set prior to if statement 
    $pending_stmt->execute(); 
    $pending_stmt->store_result(); 
    $pending_stmt->fetch_all(); 

    $rows=$pending_stmt->num_rows(); 

    $i=0; 

    while ($i < $rows) { 
     $f1=$pending_stmt->fetch($i,'pcode'); 

     //echo out to table here 

     $i++; 
    } 
} 

말할 필요 :

$query="SELECT * FROM transactions ORDER BY id DESC LIMIT 10"; 
$result=mysql_query($query); 
$num=mysql_num_rows($result);  

$i=0; 

while ($i < $num) { 
    $f1=mysql_result($result,$i,"name"); 
    $f2=mysql_result($result,$i,"surname"); 
    $f3=mysql_result($result,$i,"pcode"); 
    $f4=mysql_result($result,$i,"transaction_id"); 
    $f5=mysql_result($result,$i,"articles"); 
    $f6=mysql_result($result,$i, "delivery"); 

    //echo out to table here 

    $i++; 

} 

그때까지 기본 mysqli 쿼리로 얻고, 한 간단하게 위의 while 루프를 복제하려고 시도 : "오래된"방법은

, 그것은 작동하지 않는 ... 그리고 많은 검색 후, 나는 누군가가 나에게 몇 가지 포인터를 제공만큼 친절하게 될지 궁금해.

+0

당신이 다음 "이 작동하지 않습니다"더 명시 될 수 있을까? – antlersoft

+0

작동하지 않습니다 ... 결과가 반환되지 않습니다. –

답변

0

당신이 카운트 VAR를 사용하는 이유는 이해하지 못했다

$pending_stmt->execute(array($status)); 
$result = $pending_stmt->fetchAll(); 

을 시도, 각각에 대해 시도 :

foreach($result as $item) { 
    $f1 = $item['pcode']; 
} 
+0

나는 이것을 시도했지만 효과가 없었다. 나는 bind_result() atm을보고있다. –

+1

아파치 오류 로그를 참조하십시오. 이 설정은 $ mysqli를 올바로 설정했는지 확인하지 않으려 고하는 경우에 유용합니다. –