Save variable on a click

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 ...


Go Back   Usenet Forums > PHP Programming Forums > alt.comp.lang.php

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 08-01-2004
John Victor
 
Posts: n/a
Default Save variable on a click

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


Reply With Quote
  #2 (permalink)  
Old 08-01-2004
eclipsboi
 
Posts: n/a
Default Re: Save variable on a click

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.
Reply With Quote
  #3 (permalink)  
Old 08-01-2004
Sebastian Lauwers
 
Posts: n/a
Default Re: Save variable on a click

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
Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 06:03 PM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0