Connecting Tech Pros Worldwide Help | Site Map

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

 
LinkBack Thread Tools Search this Thread
  #1  
Old July 17th, 2005, 10:48 AM
Raju V.K
Guest
 
Posts: n/a
Default 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.

  #2  
Old July 17th, 2005, 10:48 AM
Alvaro G Vicario
Guest
 
Posts: n/a
Default Re: Passing array as value of a variable (PHP & HTML)

*** Raju V.K wrote/escribió (19 Jan 2005 02:43:43 -0800):[color=blue]
> 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.[/color]

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
--
  #3  
Old July 17th, 2005, 10:48 AM
Hartmut Holzgraefe
Guest
 
Posts: n/a
Default Re: Passing array as value of a variable (PHP & HTML)

Raju V.K wrote:[color=blue]
> 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:[/color]

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
  #4  
Old July 17th, 2005, 10:48 AM
Colin McKinnon
Guest
 
Posts: n/a
Default Re: Passing array as value of a variable (PHP & HTML)

Alvaro G Vicario wrote:
[color=blue]
> *** Raju V.K wrote/escribió (19 Jan 2005 02:43:43 -0800):[color=green]
>> Is it possible[/color]
>
> I believe you have two options:
>
> 1) Create one hidden field per character and use square brackets in the
> name:
>[/color]
<snip>[color=blue]
>
> 2) Use a string and the implode and explode:
>[/color]

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.
  #5  
Old July 17th, 2005, 10:48 AM
rajuvk@satyam.net.in
Guest
 
Posts: n/a
Default Re: Passing array as value of a variable (PHP & HTML)

Hartmut Holzgraefe wrote:[color=blue]
> Raju V.K wrote:[color=green]
> > I am developing a web site which requires a set og unique values be
> > transferred between pages and server many times. There fore i[/color][/color]
decided[color=blue][color=green]
> > to put the values in an array so that only one reference to the[/color][/color]
array[color=blue][color=green]
> > is needed ratherthan idividual reference. The situation is like[/color][/color]
this:[color=blue]
>
> Any reason for not using sessions?
>
> http://php.net/session
>
> --
> Hartmut Holzgraefe, Senior Support Engineer[/color]
..[color=blue]
> MySQL AB, www.mysql.com
>
> Are you MySQL certified? www.mysql.com/certification[/color]

  #6  
Old July 17th, 2005, 10:49 AM
steve
Guest
 
Posts: n/a
Default Re: Re: Passing array as value of a variable (PHP &amp; HTML)

"hartmut" wrote:[color=blue]
> Raju V.K wrote:[color=green]
> > I am developing a web site which requires a set og unique[/color]
> values be[color=green]
> > transferred between pages and server many times. There fore[/color]
> i decided[color=green]
> > to put the values in an array so that only one reference to[/color]
> the array[color=green]
> > is needed ratherthan idividual reference. The situation is[/color]
> 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[/color]

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
 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Popular Articles

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 220,989 network members.