472,333 Members | 2,423 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

get hidden array values

Hi
i have a array values in hidden format
[HTML]<form name="form2" method="post" action="test.php">
<input type="hidden" name="date_val[]" value="<%= date[0] %>">
<input type="hidden" name="name_val[]" value="<%= name[0] %>"></form>[/HTML]

my question is how can i get the array values in php using array(). In foreach statement i got the result but i want to do it using array to retrive the values one by one. i want to store the hidden values in table format like this

Expand|Select|Wrap|Line Numbers
  1. date                 name  
  2.  
  3. 10-10-2008        xxxx
  4. 15-09-2008        yyyy
  5.  
  6.  
in this format i want to print the array values. please any one help to solve this.

Thanks and Regards
Geethu
Oct 20 '08 #1
5 12258
Atli
5,058 Expert 4TB
Hi.

When you receive data from a form that looks like this:
Expand|Select|Wrap|Line Numbers
  1. <form action="?" method="post">
  2.   <input type="hidden" name="data[]" value="1" />
  3.   <input type="hidden" name="data[]" value="2" />
  4.   <input type="hidden" name="data[]" value="3" />
  5. </form>
  6.  
An array will be created in the $_POST super-global that would be identical to an array created like so:
Expand|Select|Wrap|Line Numbers
  1. $_POST['data'] = array('1', '2', '3');
  2.  
You could iterate through it like so:
Expand|Select|Wrap|Line Numbers
  1. foreach($_POST['data'] as $_key => $_value) {
  2.   echo "Data #{$_key} = {$_value}";
  3. }
  4.  
Which would print:
Expand|Select|Wrap|Line Numbers
  1. Data #0 = 1
  2. Data #1 = 2
  3. Data #2 = 3
  4.  
Does this answer you question?

P.S.
I notice that you use ASP-like tags. This is highly discouraged, because this feature is not enabled by default, and will be removed in PHP6. It is almost guaranteed to cause problems if you ever plan on upgrading or switching servers.

I recommend getting used to using the standard tags. They will work no matter what.
That is, instead of doing: <%= $var %>
Do: <?php echo $var; ?>
Oct 20 '08 #2
Hi.

When you receive data from a form that looks like this:
Expand|Select|Wrap|Line Numbers
  1. <form action="?" method="post">
  2.   <input type="hidden" name="data[]" value="1" />
  3.   <input type="hidden" name="data[]" value="2" />
  4.   <input type="hidden" name="data[]" value="3" />
  5. </form>
  6.  
An array will be created in the $_POST super-global that would be identical to an array created like so:
Expand|Select|Wrap|Line Numbers
  1. $_POST['data'] = array('1', '2', '3');
  2.  
You could iterate through it like so:
Expand|Select|Wrap|Line Numbers
  1. foreach($_POST['data'] as $_key => $_value) {
  2.   echo "Data #{$_key} = {$_value}";
  3. }
  4.  
Which would print:
Expand|Select|Wrap|Line Numbers
  1. Data #0 = 1
  2. Data #1 = 2
  3. Data #2 = 3
  4.  
Does this answer you question?

P.S.
I notice that you use ASP-like tags. This is highly discouraged, because this feature is not enabled by default, and will be removed in PHP6. It is almost guaranteed to cause problems if you ever plan on upgrading or switching servers.

I recommend getting used to using the standard tags. They will work no matter what.
That is, instead of doing: <%= $var %>
Do: <?php echo $var; ?>

thank you for ur reply.

i am not understand how can i get the value as 123 ie($_POST['data'] = array('1', '2', '3');) i don't know what value is in the data. i am using a jsp tags to get the array value for data field. if i know the values of data your solution is correct but i don't know the value of data[] field. please give me little bit clear.

thanks
Oct 20 '08 #3
Atli
5,058 Expert 4TB
You don't have to define the data element in your $_POST super-global yourself.
PHP will do that automatically when you post a form like the one I showed.

Any <input> element in the form will be automatically added to the $_POST array. If a number of <input> elements share the same name, and that name ends with [], then all of those elements will be added as an array into the same element.

That is all there is to it.
What you do with this data once PHP has added it to the $_POST array is up to you.

If this isn't making sense, try printing the entire $_POST array after submitting your form. Maybe that will help you understand:
Expand|Select|Wrap|Line Numbers
  1.  echo "<pre>", print_r($_POST, true), "</pre>";
Oct 20 '08 #4
You don't have to define the data element in your $_POST super-global yourself.
PHP will do that automatically when you post a form like the one I showed.

Any <input> element in the form will be automatically added to the $_POST array. If a number of <input> elements share the same name, and that name ends with [], then all of those elements will be added as an array into the same element.

That is all there is to it.
What you do with this data once PHP has added it to the $_POST array is up to you.

If this isn't making sense, try printing the entire $_POST array after submitting your form. Maybe that will help you understand:
Expand|Select|Wrap|Line Numbers
  1.  echo "<pre>", print_r($_POST, true), "</pre>";
Thank you very much.

i got the result. but the result is print in report format like one by one. i am using a code.
Expand|Select|Wrap|Line Numbers
  1.  
  2. $date[i] = print_r($_POST['Date'], true);       
  3.     echo "<td>".$date[i]."</td>";      
  4.  $name[i] = print_r($_POST['Name'], true);      
  5.     echo "<td>".$name[i]."</td>";
  6.  
in the above coding i got the result like this.
Expand|Select|Wrap|Line Numbers
  1.   Date                                                                          Name
  2.  Array ( [0] => 2008-08-29 [1] =>                  Array ( [0] => x [1] => y [2] => z)
  3.  2008-08-30 [2] =>
  4.  2008-09-07 [3] => 2008-09-08 [4] =>
  5.  2008-09-26 )                                          
  6.  
i want to print in the below format

Expand|Select|Wrap|Line Numbers
  1.   Date                                              Name
  2.  2008-08-29                                       x
  3.  2008-08-30                                       y
  4.  2008-09-07                                       z
  5.  2008-09-08                                       a
  6.  2008-09-26                                       b             
  7.  
pls give me your idea....

Thanks
Oct 21 '08 #5
Atli
5,058 Expert 4TB
The print_r function is of no use in this regard. It just creates a nicely formatted view of the array for debugging purposes.

To do this, you will have to loop through the results, using for or foreach, and print the appropriate elements from the arrays.

Like:
Expand|Select|Wrap|Line Numbers
  1. echo "Date\tName";
  2. for($i = 0; $i < count($_POST['Date']); $i++) {
  3.   echo $_POST['Date'][$i] . "\t\. $_POST['Name'][$i];
  4. }
  5.  
This assumes that the Name array has an element for each element in the Date array. You may want to make sure this is true before executing this.
Oct 21 '08 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Abdul Mohsin | last post by:
is it possible to get hidden parameter values using window.opener.document.form.parameter.value. I am getting this error " Object not found" ...
10
by: Geoff Cox | last post by:
Hello, I have a series of pages each of which creates an array of values. How do I keep all the array values until the last page? Cheers ...
3
by: Rajesh | last post by:
Hello all, I have a problem here. I have a procedure called FillForm() where I populate values for some hidden asp:textboxes. But after I do a...
1
by: DavidB | last post by:
I am working with a database and I would like to be able to populate an array at run time and then use the values that were pushed into the array...
7
by: sanjeevcis | last post by:
Hi, Below code is regarding to insert an array values into mysql db using php. i dont know why the code is not inserting array values into database...
1
by: Fareast Adam | last post by:
Anyone know how to sorting array values from least to greatest. Here the code; function mulsort($a) { sort($a); $c = count($a); ...
0
by: ghjk | last post by:
I'm using jsp. I want to print string array values . How can I do that? please help me. This is my code. ArrayList settings =...
1
by: hjaffer2001 | last post by:
I have three array values using nested loop. Now i want to export the array values to csv(excel). The code is ...
1
by: Greg Eyres | last post by:
Apologies if this is a stupid question ... I'm new to this PHP world! I have got an html form that has checkboxes dynamically created from MySQL. ...
0
by: concettolabs | last post by:
In today's business world, businesses are increasingly turning to PowerApps to develop custom business applications. PowerApps is a powerful tool...
0
by: teenabhardwaj | last post by:
How would one discover a valid source for learning news, comfort, and help for engineering designs? Covering through piles of books takes a lot of...
0
by: CD Tom | last post by:
This happens in runtime 2013 and 2016. When a report is run and then closed a toolbar shows up and the only way to get it to go away is to right...
0
jalbright99669
by: jalbright99669 | last post by:
Am having a bit of a time with URL Rewrite. I need to incorporate http to https redirect with a reverse proxy. I have the URL Rewrite rules made...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was...
0
by: Matthew3360 | last post by:
Hi there. I have been struggling to find out how to use a variable as my location in my header redirect function. Here is my code. ...
2
by: Matthew3360 | last post by:
Hi, I have a python app that i want to be able to get variables from a php page on my webserver. My python app is on my computer. How would I make it...
0
by: AndyPSV | last post by:
HOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and on my computerHOW CAN I CREATE AN AI with an .executable...
0
hi
by: WisdomUfot | last post by:
It's an interesting question you've got about how Gmail hides the HTTP referrer when a link in an email is clicked. While I don't have the specific...

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.