它只显示一个我要显示2个图像的图像 我想显示几个图像,但有其他表信息,但首先我想知道如何显示多个图像
<?php
$stmt = $mysqli->prepare("SELECT link FROM images WHERE ID = 1");
$stmt->bind_param("i", $ID);
$stmt->execute();
$stmt->bind_result($link);
$stmt->fetch();
?>
<img id="result_img" src="<?php echo $link; ?>" />
<?php
$stmt = $mysqli->prepare("SELECT link FROM images WHERE ID = 2");
$stmt->bind_param("i", $ID);
$stmt->execute();
$stmt->bind_result($link);
$stmt->fetch();
?>
<img id="result_img" src="<?php echo $link; ?>" />
答案 0 :(得分:-1)
试试这个,
$stmt = $mysqli->prepare("SELECT link FROM images WHERE ID = ?");
$stmt->bind_param("i", $ID);
$stmt->execute();
$stmt->bind_result($link);
$stmt->fetch();
$stmt->store_result();
if( $stmt->num_rows > 0 )
{
while( $stmt->fetch() )
{
echo '<img id="result_img" src="'.$link.'" />';
}
}
/* for second link just use already prepared query */
$stmt->bind_param("i", $ID2);
$stmt->execute();
$stmt->bind_result($link);
$stmt->fetch();
$stmt->store_result();
if( $stmt->num_rows > 0 )
{
while( $stmt->fetch() )
{
echo '<img id="result_img" src="'.$link.'" />';
}
}