Passing multiple values of a select box to another php page

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • shara
    New Member
    • Dec 2006
    • 28

    Passing multiple values of a select box to another php page

    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:
    [CODE=html]
    <td align="left">
    <select multiple name='srtestrun[]' style='width:30 0px;' size='10' >

    <?php

    if($srproject != 0 && $srproject > 0)
    { $sql = "SELECT TR.TEST_RUNID, TR.TEST_RUN_NAM E
    FROM TEST_RUN TR, PROJECT_RUN PR
    WHERE TR.TEST_RUNID = PR.TEST_RUNID
    AND PR.PROJECTID = ".$srprojec t."
    ORDER BY TR.TEST_RUN_NAM E";
    $smc->query($sql) or die("<h4>Error in <br><br>".$sql. "</h4>");
    $TR=$smc->result;
    for($i=0; $i < sizeof($TR); $i++)
    { echo "<option value=\"".$TR[$i][0]."\">".$TR[$i][1]."</option>";
    }
    }

    ?>
    </select>
    </td>
    [/CODE]

    The code in page 2 to retrieve these values is:
    [CODE=php]
    $srtestrun = $_POST['srtestrun'];
    for ($i = 0; $i < sizeof($srtestr un); $i++) {
    echo $srtestrun[$i];
    }
    [/CODE]

    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.
    Last edited by pbmods; Jun 1 '07, 04:31 PM. Reason: Changed code language. Thanks for using CODE tags!
  • cyberking
    New Member
    • Jan 2007
    • 84

    #2
    Originally posted by shara
    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:
    Code:
    <td align="left">
          <select multiple name='srtestrun[]' style='width:300px;' size='10' >
    
    <?php
         
      if($srproject != 0 && $srproject > 0)
      {	$sql = "SELECT TR.TEST_RUNID, TR.TEST_RUN_NAME 
                FROM TEST_RUN TR, PROJECT_RUN PR 
                WHERE TR.TEST_RUNID = PR.TEST_RUNID 
                AND PR.PROJECTID = ".$srproject."
                ORDER BY TR.TEST_RUN_NAME";
        $smc->query($sql) or die("<h4>Error in <br><br>".$sql."</h4>");
        $TR=$smc->result;
       for($i=0; $i < sizeof($TR); $i++)
        {	echo "<option value=\"".$TR[$i][0]."\">".$TR[$i][1]."</option>";
        }
      }
        
    			?>
           </select>
    		</td>
    The code in page 2 to retrieve these values is:
    Code:
    $srtestrun = $_POST['srtestrun'];
    for ($i = 0; $i < sizeof($srtestrun); $i++) {
       echo $srtestrun[$i];
    }
    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,
    [code=php]
    <?php
    $var = implode(",","sr testrun");
    ?>[/code]
    there you have all the variables, Now to display them,
    [code=php]
    <?php
    $var_display = explode(",",$va r);
    ?>[/code]

    [Please use CODE tags when posting source code. Thanks! --pbmods]

    Hope this helps you.
    Regards
    CyberKing
    Last edited by pbmods; Jun 1 '07, 04:32 PM. Reason: Added code tags.

    Comment

    • rfresh
      New Member
      • May 2007
      • 2

      #3
      I do it this way:
      [code=php]
      $option = $_POST['frm_company_ad dress_book_cbo'];
      foreach ($option as $selected)
      etc.
      etc.[/code]

      [Please use CODE tags when posting source code. Thanks! --pbmods]
      Last edited by pbmods; Jun 1 '07, 04:32 PM. Reason: Added code tags.

      Comment

      • pbmods
        Recognized Expert Expert
        • Apr 2007
        • 5821

        #4
        Changed thread title.

        Comment

        Working...