PHP q?
- Started
- Last post
- 7 Responses
- heavyt
hi,
need some help on some PHP/
i am trying to cahnge out an image by link.
so, i have $img for my image, and i want to change which image displays based on hyperlinks.
IE, click on line 4, and get img4.
seems easy, but i am having probs. please help.
TR1
- RAM0
I would prolly use JavaScript.. Otherwise, if you're totally lost, you could simply make an iframe.
- welded0
It is pretty easy no matter how you want to do it, but the most straight forward way would be the following:
You links look like this:
[a href="page.php?img=1"]1[/a]
[a href="page.php?img=2"]2[/a]
[a href="page.php?img=3"]3[/a]
[a href="page.php?img=4"]4[/a]
(NT probably busted them up a bit)Your image tag looks like this:
[img src=".jpg"]This example only works if all your images are jpgs.
As I alluded to earlier, there are many, many different ways you could go about this. This is just fast and easy. There are most certainly more flexible and powerful methods. I recommend you read up on the readdir() and getImageSize() functions. Let me know if you need any further help.
- welded0
Sorry, NT had it's way with the image tag example. It should read:
[img src=[? echo $_GET['img']; ?].jpg"]
- heavyt0
welded, thanks for thehelp. that is workgin, but now i have a different problem.
i need to set another var based on that img variable. IE. if[$img = 2] [ $detail =2; ]i tried a basic if else but to no avail.
any pointers?TR1
- cosmo0
image.php?img=" . $img($i) . "&details=4;
- cosmo0
change the details value accordingly.
- welded0
Well, again, there are a hundred and one ways to do this (I counted), but here if your $details variable will always match the $img variable then just set one with the other. By this I mean:
$details = $img;
Now they're both equal to the same thing. If they don't always match then you can either hard code it into the url like cosmo is suggesting or you could use a conditional like if-then-else or switch to set it.
if ($img = 1) {
$detail = 5;
} else-if ($img = 2) {
$detail = 10;
}or
switch ($img) {
case 1;
$details = 5;
break;
case 2;
$details = 10;
break;
}