473,836 Members | 1,539 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Passing multiple values of a select box to another php page

28 New Member
Hello there,

I want to pass multiple values selected in a select box(HTML) to another php page.I tried doing in several ways but of no use.Can anybody please help me with this.

The code i used is in page 1 is:
Expand|Select|Wrap|Line Numbers
  1. <td align="left">
  2.       <select multiple name='srtestrun[]' style='width:300px;' size='10' >
  3.  
  4. <?php
  5.  
  6.   if($srproject != 0 && $srproject > 0)
  7.   {    $sql = "SELECT TR.TEST_RUNID, TR.TEST_RUN_NAME 
  8.             FROM TEST_RUN TR, PROJECT_RUN PR 
  9.             WHERE TR.TEST_RUNID = PR.TEST_RUNID 
  10.             AND PR.PROJECTID = ".$srproject."
  11.             ORDER BY TR.TEST_RUN_NAME";
  12.     $smc->query($sql) or die("<h4>Error in <br><br>".$sql."</h4>");
  13.     $TR=$smc->result;
  14.    for($i=0; $i < sizeof($TR); $i++)
  15.     {    echo "<option value=\"".$TR[$i][0]."\">".$TR[$i][1]."</option>";
  16.     }
  17.   }
  18.  
  19.             ?>
  20.        </select>
  21.         </td>
  22.  
The code in page 2 to retrieve these values is:
Expand|Select|Wrap|Line Numbers
  1. $srtestrun = $_POST['srtestrun'];
  2. for ($i = 0; $i < sizeof($srtestrun); $i++) {
  3.    echo $srtestrun[$i];
  4. }
  5.  
But i am not able to get anything.If i am trying without using "$_POST" i am able to retrieve the last value i selected in the select box.

Thanks in Advance,
Shara.
Jun 1 '07 #1
3 4801
cyberking
84 New Member
Hello there,

I want to pass multiple values selected in a select box(HTML) to another php page.I tried doing in several ways but of no use.Can anybody please help me with this.

The code i used is in page 1 is:
Expand|Select|Wrap|Line Numbers
  1. <td align="left">
  2.       <select multiple name='srtestrun[]' style='width:300px;' size='10' >
  3.  
  4. <?php
  5.  
  6.   if($srproject != 0 && $srproject > 0)
  7.   {    $sql = "SELECT TR.TEST_RUNID, TR.TEST_RUN_NAME 
  8.             FROM TEST_RUN TR, PROJECT_RUN PR 
  9.             WHERE TR.TEST_RUNID = PR.TEST_RUNID 
  10.             AND PR.PROJECTID = ".$srproject."
  11.             ORDER BY TR.TEST_RUN_NAME";
  12.     $smc->query($sql) or die("<h4>Error in <br><br>".$sql."</h4>");
  13.     $TR=$smc->result;
  14.    for($i=0; $i < sizeof($TR); $i++)
  15.     {    echo "<option value=\"".$TR[$i][0]."\">".$TR[$i][1]."</option>";
  16.     }
  17.   }
  18.  
  19.             ?>
  20.        </select>
  21.         </td>
  22.  
The code in page 2 to retrieve these values is:
Expand|Select|Wrap|Line Numbers
  1. $srtestrun = $_POST['srtestrun'];
  2. for ($i = 0; $i < sizeof($srtestrun); $i++) {
  3.    echo $srtestrun[$i];
  4. }
  5.  
But i am not able to get anything.If i am trying without using "$_POST" i am able to retrieve the last value i selected in the select box.

Thanks in Advance,
Shara.
Hi,
You can do it this way, Once all the stuff is selected from the select box, you can use the implode function to fetch it into a variable. You can use comma as the delimiter.
Lets say you have a submit button that you use to submit your form, then the code in the second page could be like this,
Expand|Select|Wrap|Line Numbers
  1. <?php 
  2. $var = implode(",","srtestrun");
  3. ?>
there you have all the variables, Now to display them,
Expand|Select|Wrap|Line Numbers
  1. <?php 
  2. $var_display = explode(",",$var);
  3. ?>
[Please use CODE tags when posting source code. Thanks! --pbmods]

Hope this helps you.
Regards
CyberKing
Jun 1 '07 #2
rfresh
2 New Member
I do it this way:
Expand|Select|Wrap|Line Numbers
  1. $option = $_POST['frm_company_address_book_cbo'];
  2. foreach ($option as $selected)
  3. etc.
  4. etc.
[Please use CODE tags when posting source code. Thanks! --pbmods]
Jun 1 '07 #3
pbmods
5,821 Recognized Expert Expert
Changed thread title.
Jun 1 '07 #4

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

Similar topics

12
6566
by: Kevin Lyons | last post by:
Hello, I am trying to get my select options (courses) passed correctly from the following URL: http://www.dslextreme.com/users/kevinlyons/selectBoxes.html I am having difficulty getting the courses to pass the correct option value and then be displayed at the following URL: http://www.dslextreme.com/users/kevinlyons/selectResults.html I am passing countries, products, and courses. The first two display
2
2552
by: Richard | last post by:
**** Post for FREE via your newsreader at post.usenet.com **** HI, I am working on a project where I need to input data to a (local) HTML page using multiple form elements, such as text, radio, checkbox, and dropdown. When the form Submit button is clicked, I then need the input data either written to another location on the same page, or written to another page (a different frame would be fine)
7
4106
by: Drew | last post by:
I have a db table like the following, UID, int auto-increment RegNo Person Relation YearsKnown Now here is some sample data from this table,
7
43279
by: Anne | last post by:
hie there, i want to be able to pass multiple parameters to another page. currently, i am able to do so, but somehow i feel it is not the correct way to do it. below is part of what i have so far. 'first page Private Sub btnOK_ServerClick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOK.Click Response.Redirect("InputValues.aspx?Requestor=" &
1
6908
by: Eric | last post by:
Hello, I am trying to come up with the best way to pass large amounts of data from page to page, namely a data table. The user needs to enter data into a form in one page and confirm it on another. Session variables seem like the easiest, but I'm afraid of crashing the server after deploying with a few hundred users as opposed to just a few developers/testers. Any ideas?
2
12371
by: macyp | last post by:
I have to pass values from one aspx page to another. The controls I have in the first page are: a textbox, 3 drop down lists, and 2 check boxes, and a submit button. It is a search page, and the users need not enter values in all the controls. they can leave the textbox blank, and select values from one drop down, or any other combinations. I am trying to pass values with the help of session variables. But I have multiple if else...
1
14964
by: chariclark | last post by:
This may be a quick fix post... ---------------------------- I am having trouble passing multiple values into stored procedure. Here it is below: CREATE Procedure spGetAssociateds ( @PDSI int ) AS
5
3316
by: Max | last post by:
Is there any way to set a select-multiple type <select multiple="multiple"with multiple selected options in scripting? Any idea about this is appreciative.
0
2148
by: =?Utf-8?B?UGF1bA==?= | last post by:
I have a ListBox server control named "lb_dates" with a SelectionMode of "Multiple". The user can select multiple dates from the listbox. I have ObjectDataSource named "ods_rfq" with a ControlParameter that has a ControlID that points to "lb_dates". The PropertyName of the ControlParameter is "SelectedValue". The user selects two dates from the ListBox. I am trying to pass BOTH selected values of the ListBox to a SelectMethod of
0
9825
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
10852
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...
0
10553
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 captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10596
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
10255
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
9382
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...
0
6980
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();...
0
5829
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
3116
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 effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.