473,549 Members | 5,214 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

get hidden array values

45 New Member
Hi
i have a array values in hidden format
[HTML]<form name="form2" method="post" action="test.ph p">
<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 12375
Atli
5,058 Recognized Expert Expert
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
Geethu03
45 New Member
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 Recognized Expert Expert
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
Geethu03
45 New Member
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 Recognized Expert Expert
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
2509
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" Please help Abdul
10
3351
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 Geoff
3
1435
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 postback, my values in the textboxes are lost and I see only "" values. Hope someone can help me with this. Thank you.
1
7351
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 as criteria for a select query. It seems that this should be possible to so. Here is an example... Lets assume: I have a query called qSelectAgencyData and has the field (among others)...
7
42677
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 properly. If is there any thing wrong with the code, Please let me know what is that!. Here $final is an array containg the values of "ID,Name,Phone" one by one. array will be like...
1
1559
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); for($i = 0; $i < $c; $i++) if (is_array($a)) mulsort($a); }
0
1274
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 = (ArrayList)session.getAttribute("settingList");
1
1982
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 for($j=0;$j<count($TimeEntriesList);$j++){ for($n=0;$n<count($TimeEntriesList);$n++){ $datee = $TimeEntriesList; $person_id = $TimeEntriesList; $project_id = $TimeEntriesList; $desc = $TimeEntriesList;...
1
2610
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. I use an array to create the list of checkboxes. A user will then check the box as appropriate and I want to store the values. However, only the 1st checkbox value in the array is being retrieved...
0
7526
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7455
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7723
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7962
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7480
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7814
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
3504
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
1063
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
769
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.