Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

cant display two image links from mysql php

Tags:

php

mysql

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;
}

This is the code I'm using to show the images stored as links in mysql and the images are in a folder. But what happens after this code is executed only the second value is displayed. I want both value/ images to be displayed.

like image 569
Dhruv Parashar Avatar asked Oct 31 '22 20:10

Dhruv Parashar


1 Answers

Try something like that-

All you need to do is just initialize this variable outside the loop.

 $output =''; //initialize before

SO your function look like this -

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;
}
like image 167
Shail Paras Avatar answered Nov 12 '22 12:11

Shail Paras