Scott87 Posted August 27, 2008 Share Posted August 27, 2008 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 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 More sharing options...
JasonLewis Posted August 27, 2008 Share Posted August 27, 2008 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 More sharing options...
obsidian Posted August 27, 2008 Share Posted August 27, 2008 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 More sharing options...
revraz Posted August 27, 2008 Share Posted August 27, 2008 Are you using a single template file that is called for each page? Link to comment https://forums.phpfreaks.com/topic/121531-php-images/#findComment-626935 Share on other sites More sharing options...
Scott87 Posted August 27, 2008 Author Share Posted August 27, 2008 yes Link to comment https://forums.phpfreaks.com/topic/121531-php-images/#findComment-626946 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.