Jump to content

MySQL - display image?


mcfmullen

Recommended Posts

I've seen a lot of information regarding storing a complete URL into MySQL an then calling it through php to show an image. This makes sense to me.

 

What I want to know, and I'm sure it will be easy to answer, is if I can only store a PART of a url in MySQL and call it through php...

 

EX: Image url is http://www.website.com/directory/image.png

 

Instead of storing that into a field in MySQL, I want to store ONLY image.png I then want to use php to call that bit into a given URL.

 

The reason being that if ever I relocate the image directory or change domain, I can simply edit the php file once rather than rename all of the values in MySQL.

 

So the question is: how can I call the variable into an incomplete URL in order to make the image display?

Link to comment
https://forums.phpfreaks.com/topic/190315-mysql-display-image/
Share on other sites

  • 2 weeks later...

I still get a syntax error. The code is part of a larger string being called by a MySQL table through an array with a loop:

 

$result = mysql_query("SELECT * FROM Animals");

$url='http://www.mydomain.com/';

 

while($row = mysql_fetch_array($result)){

echo "ID: ".$row['idAnimal'].", Photo: <img src="'.$url.$row['photoAnimal'].'">, Name: ".$row['nameAnimal']."<br/>";

}

 

No matter where I put the ', I keep getting a syntax error. Any advice?

Link to comment
https://forums.phpfreaks.com/topic/190315-mysql-display-image/#findComment-1011183
Share on other sites

I've been trying to get my information to show in a table:

 

$result = mysql_query("SELECT * FROM Animals");
$url='http://www.mcfilmmakers.com/wp-content/farmville/animals/';

$results_array = array(); 
while ($row = mysql_fetch_array($result)) { $results_array[$row['idAnimal']] = $row; }

?>

<table> 
<?php foreach ($results_array as $id => $record) { ?> 
<tr>
<td>
<?php echo $id;?>
</td>
<td>
[color=red]<img src='<?php echo $url$row['photoAnimal']; ?>'>[/color]
</td>
<td>
<?php echo $record['nameAnimal'];?>
</td>
</tr> 
<?php } ?> 
</table>

 

The result won't display what is inside the $row['photoAnimal'] variable thus giving me broken image links. $id and $record['nameAnimal'] display just fine. Any pointers? I've tried using the other suggestions, even the one that had worked in my previous attempt, but even that won't work here.

Link to comment
https://forums.phpfreaks.com/topic/190315-mysql-display-image/#findComment-1011656
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.