469,612 Members | 2,229 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,612 developers. It's quick & easy.

Passing multiple values of a select box to another php page

28
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 4535
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
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 Expert 4TB
Changed thread title.
Jun 1 '07 #4

Post your reply

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

Similar topics

2 posts views Thread by Richard | last post: by
1 post views Thread by Eric | last post: by
reply views Thread by =?Utf-8?B?UGF1bA==?= | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.