Page 1 of 1
(Newbie) How to change variable on Image click
Posted: Thu Apr 23, 2009 1:01 pm
by Foxy999
I need to change a variable on the click of an image so that I can put it into the $_GET array. This is what I have:
echo "<p><a href='index.php'><img src='images/books.jpg' width='450' height='125', $_SERVER['PHP_SELF'], '$cat=1'/></a></p>";
Then when they click the image, it will change what database the looked up on the next page:
if($_GET['cat'] == 1)
{$query = "SELECT * FROM cat1";}
else if($_GET['cat'] == 2)
{$query = "SELECT * FROM cat2";}
I am new to PHP, please help.
Re: (Newbie) How to change variable on Image click
Posted: Thu Apr 23, 2009 1:40 pm
by jazz090
well b4 getting into PHP, try fixing up ur html markup knowledge cos that html markup its not even valid
what u want is this: <a href="index.php?cat=1"><img scr="src.jpg" width="10" height="10"></a> (u will have to change the img attributes to ur own needs)
this will send the variable 1 into the $_GET (which is NOT an array unless told otherwise)
then the rest of ur code will come into play.
Re: (Newbie) How to change variable on Image click
Posted: Thu Apr 23, 2009 2:04 pm
by Foxy999
Its just code I had found online, I use dreamweaver most of the time.
Thanks for the help, you also had a syntax error in your html code.
Foxy
Re: (Newbie) How to change variable on Image click
Posted: Thu Apr 23, 2009 2:50 pm
by pickle
Moved to Javascript as PHP isn't client-side.
Please explain yourself a little more. I'm assuming you want to change the URL the user is taken to when they click on the link?
You can modify the href of a link in Javascript, using an onclick event call for the image.
Re: (Newbie) How to change variable on Image click
Posted: Thu Apr 23, 2009 6:01 pm
by Foxy999
pickle wrote:Moved to Javascript as PHP isn't client-side.
Please explain yourself a little more. I'm assuming you want to change the URL the user is taken to when they click on the link?
You can modify the href of a link in Javascript, using an onclick event call for the image.
I have it working, and it has nothing to do with Javascript.
Re: (Newbie) How to change variable on Image click
Posted: Fri Apr 24, 2009 9:45 am
by pickle
Glad to hear you have it working, but there's no way to change anything on the client-side, based on a user action.