473,325 Members | 2,805 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,325 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 7585
*** 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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Phillip Wu | last post by:
Hi, I saw a previous post about sending arrays but did not quite understand the answers. The problem is that I would like to pass an entire array as a hidden input field from one php script...
1
by: Paul | last post by:
Hmmm, didn't seem to work. I have set session.use_cookies = 1 and session.use_trans_sid = 1 in my php.ini file. Index.php contains:...
3
by: tornado | last post by:
Hi all, I am pretty new to PHP. I was reading PHP manual and trying out the example from 2nd chapter (A simple Tutorial). When i try to print the variable as given in the example it returns...
1
by: Mitch Cunningham | last post by:
HI, i am trying to use the following code to do an xslt transform using php 4/sablotron with additional optional arguments. can anybody tell me what i am doing wrong ? i was expecting the...
58
by: jr | last post by:
Sorry for this very dumb question, but I've clearly got a long way to go! Can someone please help me pass an array into a function. Here's a starting point. void TheMainFunc() { // Body of...
2
by: assgar | last post by:
I am having problems getting the user selected form info to inserted into the mysql database. I am also rec eving an error: Warning: Variable passed to each() is not an array or object in ...
1
SHOverine
by: SHOverine | last post by:
Recently my web host decided to "upgrade". This change rendered many of my pages useless and I am scrambling to fix the issues, so you may see several posts from me in the coming days. My first...
11
by: Ebenezer | last post by:
Let's suppose I have some nodes in an XML file, with an URL attribute: <node url="mypage.php?name1=value1&foo=bar&foo2=bar2&name2=value0" /> <node...
5
by: aelred | last post by:
I have a web page where a member can open up a chat window (child window) with another member. - From there the member can also navigate to other web pages. - From other pages in the site, they...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.