2013-10-03 2 views
1

PDO를 사용 중이고 테이블에 결과를 인쇄하려고하지만 값이 나타나지 않습니다. <td> 태그를 사용해야합니다. 여기 PDO가있는 테이블에 결과 인쇄

는 시스코의 도움으로 내 전체 코드입니다 :

당신은 다음과 같이 각각의 반복에서 루프 또는 전화 fetch()fetchAll() 외부를 호출 할 필요가
<?php 
    require_once('config.php'); 


    $stmt = $connect->prepare("SELECT id, username, email FROM user"); 
    $stmt->execute(); 
    $result = $stmt->fetch(PDO::FETCH_ASSOC); 

    ?> 


       <table id="table"> 
        <thead> 
         <tr> 
          <th>ID</th> 
          <th>Username</th> 
          <th>email</th> 

         </tr> 
        </thead> 
        <tbody> 
         <?php 
         foreach ($result as $row): 

          ?> 
          <tr> 
           <td><?= $row['id'];?></td> 
           <td><?= $row['username'];?></td> 
           <td><?= $row['email'];?></td> 

          </tr> 
          <?php 
         endforeach; 
         ?> 
        </tbody> 
       </table> 
+1

결과 HTML은 무엇입니까? –

+0

모든 사용자를 얻고 싶다면'fetch()'대신'fetchAll()'을 사용합니다. [오류 처리를 엄격하게 설정하고 로깅] (http://stackoverflow.com/q/1248952/938236)이 있습니까? config.php를 포함하기 전에 오류 메시지가 표시되는지 확인하십시오. –

답변

0

:

while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) 
    // do sth 

당신이 만약 foreach를 원하면 fetchAll()을 호출하고 foreach 루프를 수행하십시오.