By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,318 Members | 2,107 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,318 IT Pros & Developers. It's quick & easy.

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

P: n/a
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
Share this Question
Share on Google+
5 Replies


P: n/a
*** 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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
"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.