By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,955 Members | 1,793 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,955 IT Pros & Developers. It's quick & easy.

Passing multiple values of a select box to another php page

P: 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
Share this Question
Share on Google+
3 Replies


cyberking
P: 84
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
P: 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
Expert 5K+
P: 5,821
Changed thread title.
Jun 1 '07 #4

Post your reply

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