473,396 Members | 1,766 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,396 software developers and data experts.

How do I write conditional PHP if statements to change image dependant on selections

I'm a newbie to PHP and need to write some code to swap an image out. What I am doing is building a "Build & Price" script. The product has several options and multiple combinations. I have images of all the different possible combinations. I need the script to show a default image at the start, then depending on the options selected from form inputs (radio buttons and checkboxes)... it would change the image to show the appropriate options selected.

Can someone show me how to write this code?

Here are the conditions... the quotes after the if are the id's for the radio and checkbox inputs. The inside brackets () is the image that needs to be shown. First line is the dafault image.

Expand|Select|Wrap|Line Numbers
  1. if default-image ('/images/build/Black/BLBA.jpg')
  2.  
  3. if 'gr-1' ('/images/build/Black/BLBA.jpg')
  4. if 'gr-1' & 'awn-blue' ('/images/build/Black/BLBA.jpg')
  5. if 'gr-1' & 'awn-blue' & 'opt-genbask' ('/images/build/Black/BLBABA.jpg')
  6. if 'gr-1' & 'opt-genbask' ('/images/build/Black/BLBABA.jpg')
  7. if 'gr-1' & 'awn-blue' & 'opt-king' ('/images/build/Black/BLBAKD.jpg')
  8. if 'gr-1' & 'opt-king' ('/images/build/Black/BLBAKD.jpg')
  9. if 'gr-1' & 'awn-blue' & 'opt-genbask' & 'opt-king' ('/images/build/Black/BLBAKDBA.jpg')
  10. if 'gr-1' & 'opt-genbask' & 'opt-king' ('/images/build/Black/BLBAKDBA.jpg')
  11. if 'gr-1' & 'awn-blue' & 'opt-king' & 'opt-solar' ('/images/build/Black/BLBAKDSO.jpg')
  12. if 'gr-1' & 'opt-king' & 'opt-solar' ('/images/build/Black/BLBAKDSO.jpg')
  13. if 'gr-1' & 'awn-blue' & 'opt-king' & 'opt-solar' & 'opt-genbask' ('/images/build/Black/BLBAKDSO.jpg')
  14. if 'gr-1' & 'opt-king' & 'opt-solar' & 'opt-genbask' ('/images/build/Black/BLBAKDSOBA.jpg')
  15. if 'gr-1' & 'awn-blue' & 'opt-solar' ('/images/build/Black/BLBASO.jpg')
  16. if 'gr-1' & 'opt-solar' ('/images/build/Black/BLBASO.jpg')
  17. if 'gr-1' & 'awn-blue' & 'opt-solar' & 'opt-genbask' ('/images/build/Black/BLBASOBA.jpg')
  18. if 'gr-1' & 'opt-solar' & 'opt-genbask' ('/images/build/Black/BLBASOBA.jpg')
  19.  
  20. if 'gr-1' & 'awn-gray' ('/images/build/Black/BLGA.jpg')
  21. if 'gr-1' & 'awn-gray' & 'opt-genbask' ('/images/build/Black/BLGABA.jpg')
  22. if 'gr-1' & 'awn-gray' & 'opt-king' ('/images/build/Black/BLGAKD.jpg')
  23. if 'gr-1' & 'awn-gray' & 'opt-genbask' & 'opt-king' ('/images/build/Black/BLGAKDBA.jpg')
  24. if 'gr-1' & 'awn-gray' & 'opt-king' & 'opt-solar' ('/images/build/Black/BLGAKDSO.jpg')
  25. if 'gr-1' & 'awn-gray' & 'opt-king' & 'opt-solar' & 'opt-genbask' ('/images/build/Black/BLGAKDSOBA.jpg')
  26. if 'gr-1' & 'awn-gray' & 'opt-solar' ('/images/build/Black/BLGAKDSO.jpg')
  27. if 'gr-1' & 'awn-gray' & 'opt-solar' & 'opt-genbask' ('/images/build/Black/BLGASOBA.jpg')
  28.  
  29. if 'gr-2' ('/images/build/Black2/BLBA.jpg')
  30. if 'gr-2' & 'awn-blue' ('/images/build/Black2/BLBA.jpg')
  31. if 'gr-2' & 'awn-blue' & 'opt-genbask' ('/images/build/Black2/BLBABA.jpg')
  32. if 'gr-2' & 'opt-genbask' ('/images/build/Black2/BLBABA.jpg')
  33. if 'gr-2' & 'awn-blue' & 'opt-king' ('/images/build/Black2/BLBAKD.jpg')
  34. if 'gr-2' & 'opt-king' ('/images/build/Black2/BLBAKD.jpg')
  35. if 'gr-2' & 'awn-blue' & 'opt-genbask' & 'opt-king' ('/images/build/Black2/BLBAKDBA.jpg')
  36. if 'gr-2' & 'opt-genbask' & 'opt-king' ('/images/build/Black2/BLBAKDBA.jpg')
  37. if 'gr-2' & 'awn-blue' & 'opt-king' & 'opt-solar' ('/images/build/Black2/BLBAKDSO.jpg')
  38. if 'gr-2' & 'opt-king' & 'opt-solar' ('/images/build/Black2/BLBAKDSO.jpg')
  39. if 'gr-2' & 'awn-blue' & 'opt-king' & 'opt-solar' & 'opt-genbask' ('/images/build/Black2/BLBAKDSO.jpg')
  40. if 'gr-2' & 'opt-king' & 'opt-solar' & 'opt-genbask'et ('/images/build/Black2/BLBAKDSOBA.jpg')
  41. if 'gr-2' & 'awn-blue' & 'opt-solar' ('/images/build/Black2/BLBASO.jpg')
  42. if 'gr-2' & 'opt-solar' ('/images/build/Black2/BLBASO.jpg')
  43. if 'gr-2' & 'awn-blue' & 'opt-solar' & 'opt-genbask' ('/images/build/Black2/BLBASOBA.jpg')
  44. if 'gr-2' & 'opt-solar' & 'opt-genbask' ('/images/build/Black2/BLBASOBA.jpg')
  45.  
  46. if 'gr-2' & 'awn-gray' ('/images/build/Black2/BLGA.jpg')
  47. if 'gr-2' & 'awn-gray' & 'opt-genbask' ('/images/build/Black2/BLGABA.jpg')
  48. if 'gr-2' & 'awn-gray' & 'opt-king' ('/images/build/Black2/BLGAKD.jpg')
  49. if 'gr-2' & 'awn-gray' & 'opt-genbask' & 'opt-king' ('/images/build/Black2/BLGAKDBA.jpg')
  50. if 'gr-2' & 'awn-gray' & 'opt-king' & 'opt-solar' ('/images/build/Black2/BLGAKDSO.jpg')
  51. if 'gr-2' & 'awn-gray' & 'opt-king' & 'opt-solar' & 'opt-genbask' ('/images/build/Black2/BLGAKDSOBA.jpg')
  52. if 'gr-2' & 'awn-gray' & 'opt-solar' ('/images/build/Black2/BLGAKDSO.jpg')
  53. if 'gr-2' & 'awn-gray' & 'opt-solar' & 'opt-genbask' ('/images/build/Black2/BLGASOBA.jpg')
  54.  
  55.  
Also... is PHP the best way to do this? I don't want any lag in loading the image. Maybe some type of javascript to handle this or maybe preload all images?
Apr 18 '14 #1
1 1447
Dormilich
8,658 Expert Mod 8TB
I don't want any lag in loading the image.
if you’re using PHP or any other server side language this doesn’t matter as the page has to be reloaded anyways.

if you don’t need a server roundtrip, use a combination of JavaScript and CSS image sprites.
Apr 19 '14 #2

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

Similar topics

15
by: Max | last post by:
Hi, I'm a perl programmer and am trying to learn PHP. So far I have figured out most of the differences, but have not been able to find out how to do the following: When running through a...
3
by: Patrice | last post by:
Hi, I need to do multi-conditional statements like below, but this error is displayed : Expected 'End' /myFilepath, line x else response.write(arrCorpo(sparam,sdiv)) end if I don't...
3
by: Sergej Andrejev | last post by:
Not long ago I was asked to give PHP lections to some private IT school. I'm on second lection now, and will be teaching my :) students conditional statements (if..else and switch) and loops (while...
92
by: Raghavendra R A V, CSS India | last post by:
hie.. Do any one knows how to write a C program without using the conditional statements if, for, while, do, switch, goto and even condotional statements ? It would be a great help for me if...
2
by: prasad | last post by:
hai all users i resquesting the conditional statements examples. thaniking you inagaprasdreddy
0
by: zPaul | last post by:
I would like to change image that says "loading" while loading a file. If that is not possible, change text in label. I was able to change the image in ASP but, can't do it in dotnet. Does...
6
by: ruca | last post by:
Hi gurus, I have a imagebutton in my WebForm, and I want that when I click (mouse down) on her the imagebutton change image and when I "unclick" (mouse up) change to the original image. Basically...
3
by: Shilpa | last post by:
Where to write XQuery statements? For eg: doc("D:\\workArea\\Books.xml")/Books/Book/Name
7
by: kadarkarai | last post by:
I am developing photo gallery in Macromedia Flash 8 and XML to retrive the Image. Image Size is all in different size. my question is How to Change image size at runtime in flash? so that image...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.