473,473 Members | 1,512 Online
Bytes | Software Development & Data Engineering Community
Create 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 4786
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
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...
2
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,...
7
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
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....
1
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...
2
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...
1
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...
5
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
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...
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...
0
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,...
0
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,...
0
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...
1
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...
0
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...
1
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...
0
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...
0
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 ...

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.