function find_image_by_id() {
global $connection;
$query = "SELECT * ";
$query .= "FROM images ";
$query .= "WHERE page_id={$_GET["page"]}";
$image_set = mysqli_query($connection, $query);
confirm_query($image_set);
return $image_set;
}
function display_image_by_id(){
$current_image = find_image_by_id();
while($image=mysqli_fetch_assoc($current_image)){
$output = "<div class=\"images\">";
$output .= "<img src=\"images/";
$output .= $image["ilink"];
$output .= "\" width=\"72\" height=\"72\" />";
$output .= $image["phone_name"];
$output .= "</div><br />";
}
mysqli_free_result($current_image);
return $output;
}
这是我用来显示在mysql中存储为链接的图像的代码 并且图像在文件夹中。但是这个代码只在第二个代码执行后会发生什么 显示值。我想要显示两个值/图像。
答案 0 :(得分:2)
尝试类似的东西 -
您需要做的只是在循环外部初始化此变量。
$output =''; //initialize before
所以你的功能看起来像这样 -
function display_image_by_id(){
$current_image = find_image_by_id();
$output =''; //initialize before
while($image=mysqli_fetch_assoc($current_image)){
$output .= "<div class=\"images\">";
$output .= "<img src=\"images/";
$output .= $image["ilink"];
$output .= "\" width=\"72\" height=\"72\" />";
$output .= $image["phone_name"];
$output .= "</div><br />";
}
mysqli_free_result($current_image);
return $output;
}