raindrops87 Posted January 5, 2011 Share Posted January 5, 2011 hi i'm using this method for a dropdown list that i get from a table in mysql. what i'm trying to do is to have a dropdown list and once i selected an item and press add it will be removed from the list but this only works for the first item i selected. when i try to select another item and press add both items will be back at the dropdown list. the $_SESSION['CompanyAdded'] are the companies that i have selected and added. can anybody help? thanks! function contact() { dbconnect(); $result = mysql_query("SELECT CompanyName from customers"); $array = $_SESSION['CompanyAdded']; echo "<td><select name=\"company\" id=\"company\">"; while($row = mysql_fetch_assoc($result)){ if($array != null){ $item = true; for($i=0;$i<count($array);$i++){ if($array != null){ if($row['CompanyName']!=$array[$i]){ $item = false; } } } if($item == false){ echo $row['CompanyName']; echo "<option value=\"".$row['CompanyName']."\">".$row['CompanyName']."</option>"; } }else{ echo $row['CompanyName']; echo "<option value=\"".$row['CompanyName']."\">".$row['CompanyName']."</option>"; } } echo"</select></td>"; Quote Link to comment Share on other sites More sharing options...
joel24 Posted January 9, 2011 Share Posted January 9, 2011 I would store those selected companies in the session then use a NOT IN clause to ensure they weren't returned in the SELECT form element i.e. $array = $_SESSION['CompanyAdded']; $companiesSelected = "('".implode("',",$array)."')"; $result = mysql_query("SELECT CompanyName from customers WHERE CompanyName NOT IN $companiesSelected"); Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.