I hve a form that people can fill out and they press the submit button which takes them to the same page, but puts their selection in a select box for later use. What I need to do is if there is something already in the select box and they choose something else, I want it to add to what is already in the select box, so I tried to create and array called $check and pass it along and have the select box go through it and get its selections. My code is below. Can anyone please help? Thanks!

<form name="add_drug_interact" method="post" action="<? $PHP_SELF?>">
<tr>
<td nowrap>
<?

	 for ($i=0; $i< $D->numrows; $i++) {
      $lbl_name=trim($D->results["LBL_NAME"][$i]);
      $edtn_cde=$D->results["PAT_EDTN_CDE"][$i];
	  $gcn_seq_nbr=$D->results["GCN_SEQ_NBR"][$i];
			if ($i==100) {
				 break;
			}?>
  <input name="add[]" type="checkbox" value="<?= $gcn_seq_nbr . "," . $lbl_name?>">
  <input type="hidden" name="gcn_seq_nbr" value="<?= $gcn_seq_nbr?>"> 
  <input type="hidden" name="search_text" value="<?= $search_text?>">
  <?echo $lbl_name;?>
	<br> 
    <? } ?>
  </td>
  <td width="64" rowspan="100" align="left" valign="top"> <input type="submit" name="Add" value="Add -->"></td>
  <? 
  	$check = $add;
  	array_push($check,$add);
	//print_r ($check);
  ?>
  <input type="hidden" name="checked" value="<?= $check?>">
  </form>
  <td rowspan="100" valign="top" align="left" width="">&nbsp;</td>
  <td rowspan="100" valign="top" align="left" width="246">
  <form name="go" method="post" action="http://www.riteaid.com">
  <select name="drugs_added" size="5" multiple>
  <?
  foreach ($check as $value) {
  	list ($gcn,$info) = split (",", $value);
  ?>
  <option value="<?= $value?>"><?= $info?></option>
  <? } ?>
  </select><br>
  <input type="hidden" name="checked" value="<?= $check?>">
  <input type="submit" name="Go" value="Go">
  </form>
  </td>
</tr>

    to put the additional items in the array try this:

    $check=$check.",".$add; //to create the array
    this adds the variable $add to the variable $check along with a ","(comma).

    to ge the output:

    <select name="drugs_added" size="5" multiple>
    <?
    $items = split(",",$check);
    foreach ($check as $value) {
    echo "<option value= \"$value?\"><option> ";
    }
    ?>
    </select><br>

    hth

    bastien

      That did not work. Now, it's not even putting my selection in the select box. Here is my code the way you suggested:

      <form name="add_drug_interact" method="post" action="<? $PHP_SELF?>">
      <tr>
      <td nowrap>
      <?

      	 for ($i=0; $i< $D->numrows; $i++) {
            $lbl_name=trim($D->results["LBL_NAME"][$i]);
            $edtn_cde=$D->results["PAT_EDTN_CDE"][$i];
      	  $gcn_seq_nbr=$D->results["GCN_SEQ_NBR"][$i];
      			if ($i==100) {
      				 break;
      			}?>
        <input name="add[]" type="checkbox" value="<?= $gcn_seq_nbr . "," . $lbl_name?>">
        <input type="hidden" name="gcn_seq_nbr" value="<?= $gcn_seq_nbr?>"> 
        <input type="hidden" name="search_text" value="<?= $search_text?>">
        <?echo $lbl_name;?>
      	<br> 
          <? } ?>
        </td>
        <td width="64" rowspan="100" align="left" valign="top"> <input type="submit" name="Add" value="Add -->"></td>
        <? 
        	$check = $check . "," . $add;
        	//array_push($check,$add);
      	//print_r ($check);
        ?>
        <input type="hidden" name="checked" value="<?= $check?>">
        </form>
        <td rowspan="100" valign="top" align="left" width="">&nbsp;</td>
        <td rowspan="100" valign="top" align="left" width="246">
        <form name="go" method="post" action="http://www.riteaid.com">
        <select name="drugs_added" size="5" multiple>
        <?
        $items = split(",",$check); 
        foreach ($check as $value) {
        	//list ($gcn,$info) = split (",", $value);
        ?>
        <option value="<?= $value?>"><?= $value?></option>
        <? } ?>
        </select><br>
        <input type="hidden" name="checked" value="<?= $check?>">
        <input type="submit" name="Go" value="Go">
        </form>
        </td>
      </tr>

        are you geting anything in the array?
        remember to have no spaces in the concatenation string

        $check = $check.",".$add;
        echo "check is ".$check;

        and this

        foreach ($check as $value)

        should be

        foreach($item as value){

        let me know

          Originally posted by bastien
          are you geting anything in the array?
          remember to have no spaces in the concatenation string


          $check = $check.",".$add;
          echo "check is ".$check;

          and this

          foreach ($check as $value)

          should be

          foreach($item as value){

          let me know

          When I use the above code, what echoes out on the screen is "check is ,Array". When I do a rint_r on $check, it also prints Array. Also, in my select box for the options, don't I need to have something like list ($gcn,$info) = split (",", $value); so I can print out my options? My code is below.

          <form name="add_drug_interact" method="post" action="<? $PHP_SELF?>">
          <tr>
          <td nowrap>
          <?

          	 for ($i=0; $i< $D->numrows; $i++) {
                $lbl_name=trim($D->results["LBL_NAME"][$i]);
                $edtn_cde=$D->results["PAT_EDTN_CDE"][$i];
          	  $gcn_seq_nbr=$D->results["GCN_SEQ_NBR"][$i];
          			if ($i==100) {
          				 break;
          			}?>
            <input name="add[]" type="checkbox" value="<?= $gcn_seq_nbr . "," . $lbl_name?>">
            <input type="hidden" name="gcn_seq_nbr" value="<?= $gcn_seq_nbr?>"> 
            <input type="hidden" name="search_text" value="<?= $search_text?>">
            <?echo $lbl_name;?>
          	<br> 
              <? } ?>
            </td>
            <td width="64" rowspan="100" align="left" valign="top"> <input type="submit" name="Add" value="Add -->"><br>
            <input type="submit" name="Delete" value="<-- Remove"></td>
          
            <? 
            $check = $check.",".$add;
            echo "check is ".$check;
            ?>
            <input type="hidden" name="checked" value="<?= $check?>">
            </form>
            <td rowspan="100" valign="top" align="left" width="">&nbsp;</td>
            <td rowspan="100" valign="top" align="left" width="246">
            <form name="go" method="post" action="http://www.riteaid.com">
            <select name="drugs_added" size="5" multiple>
            <?
            $items = split(",",$check);
            foreach ($items as $value) {
                        list ($gcn,$info) = split (",", $value);
            ?>
            <option value="<?= $value?>"><?= $info?></option>
            <? } ?>
            </select><br>
            <input type="hidden" name="checked" value="<?= $check?>">
            <input type="submit" name="Go" value="Go">
            </form>
            </td>
          </tr>

            I'm not sure about these lines:

            Originally posted by Anon

            <?
            $check = $add;
            array_push($check,$add);
            //print_r ($check);
            ?>

            In particular, that first line - why are you destroying $check's value and replacing it with $add's?

            Also, if I understand you correctly and that you want the elements of $add appended to the elements of $check, then you should be using the array_merge() function instead.

              Write a Reply...