2009-10-16 48 views
0
<?php 
$dbhost = 'xxxx'; 
$dbuser = 'xxxx'; 
$dbpass = 'xxxx'; 
$dbname = 'xxxx'; 

$conn = mysql_connect($dbhost, $dbuser, $dbpass) or die ('Error connecting to mysql'); 

mysql_select_db($dbname); 
$result = mysql_query("SELECT * FROM mytable"); 

$row = mysql_fetch_array($result) 
?> 
<?php foreach ($rows as $row): ?> 
    <tr align="center"> 
      <td><?php echo htmlspecialchars($row['Picturedata']); ?></td> 
      </tr> 
<?php endforeach; ?> 

我得到一個錯誤: 警告:()提供的foreach無效參數我試圖做一個ASP像中繼器在PHP

回答

0

你需要做一個while循環來拉動每一行。 mysql_fetch_array()一次只能拉一行。考慮這個解決方案:

<?php 
$dbhost = 'xxxx'; 
$dbuser = 'xxxx'; 
$dbpass = 'xxxx'; 
$dbname = 'xxxx'; 

$conn = mysql_connect($dbhost, $dbuser, $dbpass) or die ('Error connecting to mysql'); 

mysql_select_db($dbname, $conn); 
$result = mysql_query("SELECT * FROM mytable", $conn); 

while ($row = mysql_fetch_array($result)) { 
    echo '<tr align="center"><td>' . htmlspecialchars($row['Picturedata']) . '</td></tr>'; 
} 
?> 
+0

這工作 Thans! – Joe 2009-10-16 21:41:30

0

它應該是$行,而不是$行

$rows = mysql_fetch_array($result) 
+0

感謝, 該錯誤不顯示agian,但仍然沒有任何獲取數據:( – Joe 2009-10-16 21:16:28