• This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.

RESOLVED Display a picture together with SQL-query data

RobertS

New member
Messages
3
Likes
0
Points
1
#1
I'm trying to display data from an external database inside a WordPress page.
So far so good with Woody Snpippets that works quite fine. I can display Firstname, Lastname and Year of birth from our sport club swimm team members.

Additional I would like to display a picture of each member, which doesn't com from the database. it could be loaded from filesystem or an URL (based on the used Nextgen Gallery plugin). The picture can be identified by teh name schema whatever/path/firstname.lastname.png.
Any idea how to realize that?

This is the code which displays the data:
PHP:
if ($result->num_rows > 0) {
    // output data of each row
    while($row = $result->fetch_assoc()) {
        echo $row["Vorname"]." ". $row["Nachname"]. "<br>";
        echo "Jahrgang ". $row["Jahrgang"]. "<br /><br />";
        }
} else {
    echo "0 results";
}
 

Temyk

Support team
Staff member
Messages
263
Likes
19
Points
18
#2
Hello.

Maybe like this?
PHP:
<img src="whatever/path/".$row["Vorname"].".".$row["Nachname"].".png" />
 

RobertS

New member
Messages
3
Likes
0
Points
1
#3
Hi,

that's more or less the way I've tried...
If I copy your example - regardless the path doesn't exist, the syntax should be right - I get the first error: "unexpected < at line 19" (which is the "image line")
PHP:
if ($result->num_rows > 0) {
    // output data of each row
    while($row = $result->fetch_assoc()) {
        <img src="whatever/path/".$row["Vorname"].".".$row["Nachname"].".png" />;
        echo $row["Vorname"]." ". $row["Nachname"]. "<br>";
        echo "Jahrgang ". $row["Jahrgang"]. "<br /><br />";
        }
} else {
    echo "0 results";
}
Sure this one of my "don'tknow what I'm doing" mistakes, but I'm more or less lost...
 

Temyk

Support team
Staff member
Messages
263
Likes
19
Points
18
#4
PHP:
if ($result->num_rows > 0) {
    // output data of each row
    while($row = $result->fetch_assoc()) {
        echo "<img src='whatever/path/".$row["Vorname"].".".$row["Nachname"].".png' />";
        echo $row["Vorname"]." ". $row["Nachname"]. "<br>";
        echo "Jahrgang ". $row["Jahrgang"]. "<br /><br />";
        }
} else {
    echo "0 results";
}
Only you will not see anything, because you need to substitute the address of the site on which the images are
 

RobertS

New member
Messages
3
Likes
0
Points
1
#5
That works like a charm - THX!
How stupid can somebody be - missed the echo and did not see that...
 
Last edited: