Jump to content

php / images


Scott87

Recommended Posts

Just join up here so I'd like to say HI.

 

I'm currently a PHP beginner so I won't pretend to understand stuff :D

 

I'm learning and know the basics so far but I'm having a bit of a dilemma:

 

 

I currently have a banner image, which is static on each page.

 

The pages are generated via a CMS / PHP etc.

 

I want to change the banner image on each page, so e.g. Home - img1, About - img2, Contact - img3 etc.

 

 

Whats the best way to do this?

 

 

Link to comment
https://forums.phpfreaks.com/topic/121531-php-images/
Share on other sites

Well you can use a switch.

 

switch($page){
case 'Home':
echo "<img src='img1.jpg' />";
break;
case 'About':
echo "<img src='img2.jpg' />";
break;
default:
echo "<img src='img1.jpg' />";
break;
}

 

Or you can name your images home.jpg, about.jpg then do this:

 

//Grab the page from the address bar
$page = $_GET['page'];

if($page == ""){
$page = "home";
}

$page = strtolower($page); //Make it lowercase, just incase.
echo "<img src='" . $page . ".jpg' />";

 

Hope that makes sense.

 

Or you could use an if statement, which is basically a switch.

Link to comment
https://forums.phpfreaks.com/topic/121531-php-images/#findComment-626801
Share on other sites

Here's one more idea for you:

<?php
$banners = array(
  'home' => 'image1.jpg',
  'about' => 'image2.jpg',
  'contact' => 'image3.jpg'
);

$page = isset($_GET['page']) ? $_GET['page'] : 'home'; // default to home page
echo "<img src=\"{$banners[$page]}\" />";
?>

Link to comment
https://forums.phpfreaks.com/topic/121531-php-images/#findComment-626932
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.