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.
(Newbie) How to change variable on Image click
Moderator: General Moderators
Re: (Newbie) How to change variable on Image click
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.
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
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
Thanks for the help, you also had a syntax error in your html code.
Foxy
Re: (Newbie) How to change variable on Image click
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.
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.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
Re: (Newbie) How to change variable on Image click
I have it working, and it has nothing to do with Javascript.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.
Re: (Newbie) How to change variable on Image click
Glad to hear you have it working, but there's no way to change anything on the client-side, based on a user action.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.