<?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()提供的参数无效
答案 0 :(得分:0)
它应该是$ rows而不是$ row
$rows = mysql_fetch_array($result)
答案 1 :(得分: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>';
}
?>