473,385 Members | 1,673 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,385 software developers and data experts.

Problem with array...

I have a form with 5 dropdown lists I want to put all selected values to an
array called $data[] so i wrote sometthing like this:

for(i=0;i<5;i++){
echo"<select name=\"\$data[]\">";
echo"<option value=\"1\">1</option>";
echo"<option value=\"1\">2</option>";
echo"<option value=\"1\">3</option>";
echo"</select>";
}

So I think this will put all selected values into an array.
But the problem is that when user submits the form this array goes to $_POST
array
And I have no idea how to read a value from an array $data which is into
array $_POST and use it as a part of "if" statement

for example
if (value_from_array==5){
// instructions
}

Thanks for help
Leszek
Feb 1 '06 #1
2 1271
Leszek wrote:
I have a form with 5 dropdown lists I want to put all selected values to an
array called $data[] so i wrote sometthing like this:

for(i=0;i<5;i++){
echo"<select name=\"\$data[]\">";
echo"<option value=\"1\">1</option>";
echo"<option value=\"1\">2</option>";
echo"<option value=\"1\">3</option>";
echo"</select>";
}

So I think this will put all selected values into an array.
But the problem is that when user submits the form this array goes to $_POST
array
And I have no idea how to read a value from an array $data which is into
array $_POST and use it as a part of "if" statement

$value_from_array=$_POST['$data'];
//for example
if ($value_from_array[0]==5){
// instructions
}

But would be easier you didn't use the $ in the name

for(i=0;i<5;i++){
echo"<select name=\"\data[]\">";
echo"<option value=\"1\">1</option>";
echo"<option value=\"1\">2</option>";
echo"<option value=\"1\">3</option>";
echo"</select>";
}

$value_from_array=$_POST['data'];
if ($value_from_array[0]==5){
// instructions
}

//Aho
Feb 1 '06 #2
I don't exactly understand what you want to do but I hope this will
help ypu getting your values:

<!-- *snip* -->

<html>
<form action="NewFile.php" method="POST">

<?

for($i=0;$i<5;$i++){
echo"<select name=\"test[]\">";
echo"<option value=\"1\">1</option>";
echo"<option value=\"2\">2</option>";
echo"<option value=\"3\">3</option>";
echo"</select>";

}

?>
<INPUT type="submit">
</form>
<?

# this will show you all values that are in $_POST
echo '<pre>', print_r($_POST), '</pre>';

# extract the array that contains all 5 values of the drop downs
$your_data = $_POST["test"];

# display the array
echo '<pre>', print_r($your_data), '</pre>';

# run through the array
foreach ($your_data as $value_from_array)
{
# ...and do with the values whatever you want to do
if ($value_from_array==5)
{
// instructions
# :-)
}
}

?>

</html>

<!-- *snap* -->


Leszek schrieb:
I have a form with 5 dropdown lists I want to put all selected values to an
array called $data[] so i wrote sometthing like this:

for(i=0;i<5;i++){
echo"<select name=\"\$data[]\">";
echo"<option value=\"1\">1</option>";
echo"<option value=\"1\">2</option>";
echo"<option value=\"1\">3</option>";
echo"</select>";
}

So I think this will put all selected values into an array.
But the problem is that when user submits the form this array goes to $_POST
array
And I have no idea how to read a value from an array $data which is into
array $_POST and use it as a part of "if" statement

for example
if (value_from_array==5){
// instructions
}

Thanks for help
Leszek


Feb 1 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: JesusFreak | last post by:
From: us_traveller@yahoo.com (JesusFreak) Newsgroups: microsoft.public.scripting.jscript Subject: toolbar script problem NNTP-Posting-Host: 192.92.126.136 Recently, I downloaded the following...
8
by: mytfein | last post by:
Hi Everyone, Background: Another department intends to ftp a .txt file from the mainframe, for me to process. The objective is to write a vb script that would be scheduled to run daily to...
8
by: intrepid_dw | last post by:
Hello, all. I've created a C# dll that contains, among other things, two functions dealing with byte arrays. The first is a function that returns a byte array, and the other is intended to...
4
by: daroman | last post by:
Hi Guys, i've problem with my small C++ programm. I've just small template class which represetns a array, everything works fine up to combination with std::string. I did tried it with M$ VC++ and...
9
by: weidongtom | last post by:
Hi, I've written the code that follows, and I use the function add_word(), it seems to work fine *before* increase_arrays() is called that uses realloc() to allocate more memory to words. But...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.