473,794 Members | 2,804 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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_arr ay==5){
// instructions
}

Thanks for help
Leszek
Feb 1 '06 #1
2 1288
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_arr ay=$_POST['$data'];
//for example
if ($value_from_ar ray[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_arr ay=$_POST['data'];
if ($value_from_ar ray[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_d ata), '</pre>';

# run through the array
foreach ($your_data as $value_from_arr ay)
{
# ...and do with the values whatever you want to do
if ($value_from_ar ray==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_arr ay==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
3846
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 beautiful script "http://javascript.internet.com/navigation/toolbar-menu.html". It works like a charm. I made my webpage in frames, where the nav-frame shows the menubar, so whenever I click a link in the menubar, it opens in the frame below. But...
8
3372
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 process this .txt file. Goal: I am working on a vba script to:
8
10719
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 receive a byte array as one of its parameters. The project is marked for COM interop, and that all proceeds normally. When I reference the type library in the VB6 project, and write the code to call the function that returns the byte array, it works
4
11232
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 with GCC (Cygwin and Linux) and my problem is when i try do this int main(int argc, char **argv) { array<std::stringa(10); a = "Huhuhu"; <--- with gcc i got a crash !
9
2519
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 *after* calling increase_arrays(), I received segmentation fault. I tried to step it through gdb, and I found out that after calling increase_arrays(), words's original value is modified, and if I tried to access it, I get <address 0x11 out of...
0
9672
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 usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10435
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. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10163
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 most users, this new feature is actually very convenient. If you want to control the update process,...
0
10000
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 choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9037
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7538
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6779
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
4113
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3721
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.