Board index   FAQ   Search  
Register  Login
Board index php forum :: php coding PHP coding => Images

Displaying images in multiple html or php files

images php coding issues or problems here.

Moderators: macek, egami, gesf

Displaying images in multiple html or php files

Postby fimmtv » Wed Jul 11, 2012 5:19 pm

Hi all

I just joined the forum.

This is what I am trying to do.
I want to display different jpegs in different html files so that I do not have to manually load the jpegs in every html file.

Also if a change is made to any of the jpeg, I do not want to go through each html or php file and reload or remove the file.

Currently I have done these on shtml files.

Can someone please guide on what to do. Do I create a php file and load this into the html?

many thanks
fimmtv
New php-forum User
New php-forum User
 
Posts: 1
Joined: Wed Jul 11, 2012 5:02 pm

Re: Displaying images in multiple html or php files

Postby kyle04 » Tue Jul 17, 2012 1:42 pm

You'll have to reference the images from somewhere - a database table would be the most straightforward.

A table with (prikey) and 2 fields would be a starting point.

Field 1 : "pagename" - set to varchar 255
Field 2 : "image" - set to varchar 255

The image field would have just the image name (eg myimage.jpg), and could be referenced from the folder (in the example "images"), it resides in with php :

<?
error_reporting(E_ALL);

$this_page = $_SERVER['REQUEST_URI']; // returns page path/name from root
$result = mysql_query("SELECT*FROM TABLENAME WHERE pagename='$this_page'");
$row = mysql_fetch_array($result);
if($result) {
$display_image = "images/".$row['image']; // assuming image folder is in root directory

echo "<img src=\"$display_image\">";
}
?>

The script would have to be built into every page either directly, or saved in the same folder and referenced as an include :

<? include("image_script.php"); ?>

Your page naming and file paths will have to be spot on.

AndyP
kyle04
New php-forum User
New php-forum User
 
Posts: 94
Joined: Sat Jul 07, 2012 1:36 pm


Return to PHP coding => Images

Who is online

Users browsing this forum: No registered users and 2 guests

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.