472,145 Members | 1,961 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,145 software developers and data experts.

Passing array as value of a variable (PHP & HTML)

I am developing a web site which requires a set og unique values be
transferred between pages and server many times. There fore i decided
to put the values in an array so that only one reference to the array
is needed ratherthan idividual reference. The situation is like this:

When the page is loaded based on the user input say 6 values are
created like character1="tom", character2="jerry", Character3="micky",
Character4="donald", character5="cat", character6="rat". This to be
preserved for two or three further pages to be loaded based on further
user input. One solution is to create <input>tags with names
Character1, character2, ............character6 and assign values to
each of them. But when the list is enlarged say to 75 values it is
unweildy. So I found that when the page is first created an array is
created like $character=array('tom', 'jerry' , 'micky', 'donald',
'cat', 'dog')and can be assigned to a single input tag. Is it possible
to such a tag like "<input type="hidden" value=$character>". Or is
there any better alternative to this ? Any help is verymuch
appreciated.

regards,
Raju V.K.
Jul 17 '05 #1
5 7458
*** Raju V.K wrote/escribió (19 Jan 2005 02:43:43 -0800):
Is it possible
to such a tag like "<input type="hidden" value=$character>". Or is
there any better alternative to this ? Any help is verymuch
appreciated.


I believe you have two options:

1) Create one hidden field per character and use square brackets in the
name:

<input name="character[0]" type="hidden"
value="<?=htmlspecialchars($character[0])?>"><input name="character[1]"
type="hidden"
value="<?=htmlspecialchars($character[1])?>">

2) Use a string and the implode and explode:

<? $character=explode('|', $_GET['character']); ?>
<input name="character" type="hidden"
value="<?=htmlspecialchars(implode('|', $character))?>">

where '|' is a character not used within character names.

--
-- Álvaro G. Vicario - Burgos, Spain
-- Thank you for not e-mailing me your questions
--
Jul 17 '05 #2
Raju V.K wrote:
I am developing a web site which requires a set og unique values be
transferred between pages and server many times. There fore i decided
to put the values in an array so that only one reference to the array
is needed ratherthan idividual reference. The situation is like this:


Any reason for not using sessions?

http://php.net/session

--
Hartmut Holzgraefe, Senior Support Engineer .
MySQL AB, www.mysql.com

Are you MySQL certified? www.mysql.com/certification
Jul 17 '05 #3
Alvaro G Vicario wrote:
*** Raju V.K wrote/escribió (19 Jan 2005 02:43:43 -0800):
Is it possible
I believe you have two options:

1) Create one hidden field per character and use square brackets in the
name:

<snip>
2) Use a string and the implode and explode:


Or

3) use a single html field & serialize the array (and unserialize on
receipt).

Or

4) keep the array in a session variable and pass the session handle through
the browser.

C.
Jul 17 '05 #4
Hartmut Holzgraefe wrote:
Raju V.K wrote:
I am developing a web site which requires a set og unique values be
transferred between pages and server many times. There fore i decided to put the values in an array so that only one reference to the array is needed ratherthan idividual reference. The situation is like
this:
Any reason for not using sessions?

http://php.net/session

--
Hartmut Holzgraefe, Senior Support Engineer .. MySQL AB, www.mysql.com

Are you MySQL certified? www.mysql.com/certification


Jul 17 '05 #5
"hartmut" wrote:
Raju V.K wrote:
I am developing a web site which requires a set og unique

values be
transferred between pages and server many times. There fore

i decided
to put the values in an array so that only one reference to

the array
is needed ratherthan idividual reference. The situation is

like this:

Any reason for not using sessions?

http://php.net/session

--
Hartmut Holzgraefe, Senior Support Engineer
.
MySQL AB, www.mysql.com

Are you MySQL certified? www.mysql.com/certification


One word of caution re: sessions

The user is perfectly capable of opening multiple pages from the same
website. Sessions are used for page-independent parameters (e.g. user
name/password, ...). If your info is page-specific don’t use
sessions, or if you do, make sure untargeted pages don’t use it by
mistake. You can do so by adding the target url info to the session
content.

--
Posted using the http://www.dbforumz.com interface, at author's request
Articles individually checked for conformance to usenet standards
Topic URL: http://www.dbforumz.com/PHP-Passing-...ict189354.html
Visit Topic URL to contact author (reg. req'd). Report abuse: http://www.dbforumz.com/eform.php?p=639935
Jul 17 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Phillip Wu | last post: by
1 post views Thread by Paul | last post: by
3 posts views Thread by tornado | last post: by
1 post views Thread by Mitch Cunningham | last post: by
11 posts views Thread by Ebenezer | last post: by
reply views Thread by leo001 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.