2014-01-06 126 views
0

到目前爲止,我已經使用準備好的語句從數據庫中獲取一行。但是,我如何在頁面上寫入多行。在網上看,人們似乎只顯示如何獲得一排。MySQL準備好聲明,寫入多行

if ($count_sets->num_rows > 0) { 
     $query = "SELECT id,jpg,udate,imageset FROM images WHERE dodelete = ? AND udate = ? AND imageset = ?"; 
     if ($stmt = $mysqli->prepare($query)) { 
      //echo "Prepare failed: (" . $mysqli->errno . ") " . $mysqli->error; 
      $stmt->bind_param("isi",$deleted,$session_date,$imageset); 
      $stmt->execute(); 
      $stmt->store_result(); 

      //Get result 
      $stmt->bind_result($result_id,$result_jpg,$result_date,$result_imageset); 

      //Number of rows returned 
      $count_rows = $stmt->num_rows; 
     } 
    } else { 
     echo "No images to process, do an upload first!"; 
    } 
$folder = str_replace("/", "", $session_date); 

      if ($count_rows > 0) { 
       echo "hel<br />"; 
       echo $result_jpg[0]; 
      } 
+0

你的問題是什麼?你不能做多行? – hichris123

+0

我不知道如何將結果打印到頁面上。試過一個foreach循環,但那不起作用... –

回答

0

發現了一些示例代碼:

$db = new mysqli("host","user","pw","database"); 
$stmt = $db->prepare("SELECT * FROM mytable where userid=? AND category=? ORDER BY id DESC"); 
$stmt->bind_param('ii', intval($_GET['userid']), intval($_GET['category'])); 
$stmt->execute(); 

$stmt->store_result(); 
$stmt->bind_result($column1, $column2, $column3); 

while($stmt->fetch()) 
{ 
    echo "col1=$column1, col2=$column2, col3=$column3 \n"; 
} 

$stmt->close(); 

這是下面的部分,我不知道該怎麼辦。

while($stmt->fetch()) 
    { 
     echo "col1=$column1, col2=$column2, col3=$column3 \n"; 
    } 
+0

你找到解決方案了嗎?即時通訊也有問題 – jsetting32