Dynadot โ€” .com Registration $8.99

How to display images from MySQL database?

Spacemail by SpaceshipSpacemail by Spaceship
Watch

JsteRmX

Established Member
Impact
2
On my site, I allow users to either select an image or to type in the path of their image which is hosted elsewhere. The file name or file path gets stored in my database. Now I want to display their image on a page. How do I do this? This is the code I have for it...

PHP:
$sql = "SELECT * FROM user";
$query = mysql_query($sql);
while($row = mysql_fetch_array($query)) {
echo "<tr>";
echo "<td>".$row['user_image']."</td>"; 
echo "</tr>";

When I try this, it only displays the file name or path of the image, not the actual image. How do I fix this?
 
0
•••
The views expressed on this page by users and staff are their own, not those of NamePros.
.US domains.US domains
PHP:
$sql = "SELECT * FROM user"; 
$query = mysql_query($sql); 
while($row = mysql_fetch_array($query)) { 
echo "<tr>"; 
echo "<td><img src =\"" . $row['user_image']."\"></td>";  
echo "</tr>";
 
0
•••
thank you noobie, that worked perfect! Now i just have to try and get it formatted correctly. I want this image to appear to the right of a URL that is also displayed from the DB. a simple table with two columns would work.
do you know how to do this? here is the complete code:

PHP:
$sql = "SELECT * FROM user_extended";
$query = mysql_query($sql);
while($row = mysql_fetch_array($query)) {
echo "<tr>";
echo '<td><p class="style1"><a href="'.$row['user_homepage'].'"><size=10>'.$row['user_homepage'].'</size></a></p></td>';  
echo "</tr>";
}
$sql = "SELECT * FROM user";
$query = mysql_query($sql);
while($row = mysql_fetch_array($query)) {
echo "<tr>";
echo "<td><img src =\"" . $row['user_image']."\"></td>";
echo "</tr>";
 
0
•••
hello

bump ... sorry i misunderstood ... bump
 
0
•••
wouldn't that last code make it still go on a one column table with all the urls on top then all the images at the bottom part?

ok this is just a draft....

PHP:
$sql = "SELECT * FROM user_extended";
$img_sql = "SELECT * FROM user";
$query = mysql_query($sql);
$img_query = mysql_query($img_sql);
while($row = mysql_fetch_array($query) && $row2 = mysql_fetch_array($img_query)) {
echo "<tr>";
echo '<td><p class="style1"><a href="'.$row['user_homepage'].'"><size=10>'.$row['user_homepage'].'</size></a></p></td>';  
echo "<td><img src =\"" . $row2['user_image']."\"></td>";
echo "</tr>";
}

i think there's better way to code this though.
 
0
•••
thanks for trying einjhel, but that didnt work either.

Now, the user_homepage does not show up, and the images just show as red X.

this is driving me crazy, lol i cant believe we still havent figured it out.
 
0
•••
Dynadot โ€” .com Registration $8.99Dynadot โ€” .com Registration $8.99
Appraise.net
Unstoppable Domains
Domain Recover
DomainEasy โ€” Zero Commission
  • The sidebar remains visible by scrolling at a speed relative to the pageโ€™s height.
Back