This is a discussion on Save variable on a click within the alt.comp.lang.php forums, part of the PHP Programming Forums category; I have a menu made up of images where users can click an image to load the next page. I ...
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
I have a menu made up of images where users can click an image to load the
next page. I want each image to send a unique id number to the page the user loads. Based on this id number, the page that will be loaded will display something different. Since I'm not using a form to post data, I decided to save the id number as a session variable. The loaded page will read the variable when determining what to load. The problem I'm encountering is where to put the code to get the first page to save the id number (I know how to save and retrieve session variables, so that's not an issue). I've tried putting the php script inside the onclick attribute of the link, but that didn't work. Does anyone know how I can do this, or know a better way? Thanks. -- John Victor |
|
|||
|
On Sun, 01 Aug 2004 07:32:31 GMT, "John Victor" <wiegeabo@pacbell.net>
wrote: >I have a menu made up of images where users can click an image to load the >next page. I want each image to send a unique id number to the page the >user loads. Based on this id number, the page that will be loaded will >display something different. > >Since I'm not using a form to post data, I decided to save the id number as >a session variable. The loaded page will read the variable when determining >what to load. The problem I'm encountering is where to put the code to get >the first page to save the id number (I know how to save and retrieve >session variables, so that's not an issue). > >I've tried putting the php script inside the onclick attribute of the link, >but that didn't work. Does anyone know how I can do this, or know a better >way? Thanks. You don't need a form to send data to the server. And sessions are dealt with solely on server-side. So the problem is, how to tell your script which image the user clicked on. You can use $_GET: Meaning, append a ?name=value to the links of your images. Name could be anything you want the variable to be called, so you can access it via $_GET['name'] in PHP. Value is some unique identifier to determine which image was clicked (it could be as simple as the image file name, or something you concoct yourself). Remember, the key to writing successful sites is communication: You have to find viable ways to have your web pages communicate with your PHP back-end. $_GET and $_POST are the two most popular ways, certain $_SERVER variables (i.e. PHP_SELF, PATH_INFO, etc) are another way. Create a file, name it whatever you want, and put the following code in there to help you see what goes between the browser and PHP: <? phpinfo(); ?> Happy coding. |
|
|||
|
eclipsboi wrote:
> You don't need a form to send data to the server. And sessions are > dealt with solely on server-side. So the problem is, how to tell your > script which image the user clicked on. You can use $_GET: Meaning, > append a ?name=value to the links of your images. Name could be > anything you want the variable to be called, so you can access it via > $_GET['name'] in PHP. Value is some unique identifier to determine > which image was clicked (it could be as simple as the image file name, > or something you concoct yourself). > > Remember, the key to writing successful sites is communication: You > have to find viable ways to have your web pages communicate with your > PHP back-end. $_GET and $_POST are the two most popular ways, certain > $_SERVER variables (i.e. PHP_SELF, PATH_INFO, etc) are another way. > Create a file, name it whatever you want, and put the following code > in there to help you see what goes between the browser and PHP: > > <? > phpinfo(); > ?> > > Happy coding. Indeed, PHP is server side, so once it's outputted, you can't change the vars anymore. You could try to use a database in order to stock the meaning of the picture's IDs. The big part of the script will of course populating the database, but it's i think one of the best ways to do so. HTH, Sebastian |