473,404 Members | 2,187 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,404 software developers and data experts.

If statements for Image Selection

Hi...
Fairly new to PHP and trying to work with some images...

I have a page where I need to display a different header image on based on a business type that is coming from MySQL... There are seven total options... is there an easy if statement that can handle this in PHP?
Feb 16 '08 #1
4 1320
hsriat
1,654 Expert 1GB
Hi...
Fairly new to PHP and trying to work with some images...

I have a page where I need to display a different header image on based on a business type that is coming from MySQL... There are seven total options... is there an easy if statement that can handle this in PHP?
Create an array with each business type as keys and corresponding image columns (or rows) as their values.
[php]query = array("business1"=>"b1image","business2"=>"b2image ");
//other code
$sql = mysql_query("SELECT `".query['businessX']."` FROM `table`");[/php]
Feb 16 '08 #2
ronverdonk
4,258 Expert 4TB
Hi...
Fairly new to PHP and trying to work with some images...

I have a page where I need to display a different header image on based on a business type that is coming from MySQL... There are seven total options... is there an easy if statement that can handle this in PHP?
Since I can see no code something like the switch method:
[php]
$business_type=... whatever comes from the database
switch ($business_type) {
case 'a' : $img = 'type1.png';
break;
case 'b' : $img = 'type2.png';
break;
............................
............................
case 'g' : $img = 'type7.png';
break;
default : $img = 'noimage.png';
break;
}
echo "<img src='$img' border='0' />"
--- etc.
[/php]
Another method is to store it in an associative array and get the image name from there:
[php]
$array=array('a'=>'type1.jpg', 'b'=>'type2.jpg', ......... 'g'=>'type7.jpg');
if (isset($array[$business_type]))
$img=$array[$business_type];
else
$img='noimage.png';
echo "<img src='$img' border='0' />"
..... etc ....
[/php]
Ronald
Feb 16 '08 #3
Maybe the code will help...

Basically... this was an afterthought. I have a template built that in the body portion is pulling in a "more info" type section for a business listing. Then I realized that in the top of the template i need the main pic to correspond with the business type that's pulling from the database.

The image section is just normal html:
<td align="left" valign="top"><!-- InstanceBeginEditable name="headerpic" --><img src="images/mbw_int_main.jpg" width="821" height="155"><!-- InstanceEndEditable --></td>

My main select and query statement are down in the body.

The business types are golf, accommodations, shopping, nightlife, etc... these are the "business_type" pulling from the database.

The "case a" etc seems the easiest to me, but forgive my ignorance...

Would I place the "case" inside the <td> where the image is now?
Feb 16 '08 #4
ronverdonk
4,258 Expert 4TB
Assuming varaible $img holds the image path/name, you can write the image in your statement via PHP, as follows:
[html]
<td align="left" valign="top"><!-- InstanceBeginEditable name="headerpic" --><img src="<?php echo $img ?>" width="821" height="155"><!-- InstanceEndEditable --></td>
[/html]
Ronald
Feb 16 '08 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: GazK | last post by:
I have an image viewing page which resizes an image to a sensible sizebefore displaying. The user should then be able to choose "25% larger" or smaller and the resized image display. The problem I...
1
by: John Pastrovick | last post by:
Is there a way to load an image locally (in the client) when a selection of a file is made using input type=file. The purpose is to allow selection of a file and put the image in the browser...
2
by: Francisco | last post by:
Hello, I'm creating my WYSIWYG html web editor. but now I want to know witch image is selected. I try the selection.createRange().htmlText but it returns me null. I see that when i have an image...
6
by: QuasiChameleon | last post by:
Hi, I'm trying to create a grayscale image class that reads and writes grayscale Targa format. This works well with smaller images, but corrupts larger images and creates a "Segmentation fault...
4
by: serge | last post by:
I was working on figuring out where a certain application was storing the multiple selection choices I was doing through the app. I finally figured out that they were being store in an IMAGE data...
1
by: KitKat | last post by:
With the help of kind, brilliant folks, I have been working on this program that uses a combo box selection to display six different jpgs. The jps are a time stamp, and the files are located in six...
0
by: Andrew | last post by:
Hello Ive been messing around with a simple raw image viewer using Pil and Tkinter However I am running into problems displaying the images they appear to be not correct I believe it is cause of...
7
by: jzieba | last post by:
I found the following script that changes the text based on a user selection. I want to modify the code to change an image source based on the user selection. I have been told I can do this with...
6
by: Sajeena | last post by:
<?php // starting word $text = "My Text"; //Start MS Word $Word = new COM("word.application") or die("Failure: Word did not start"); echo("WORD has started."); //Formating the Font...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.