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>"; Link to comment https://forums.phpfreaks.com/topic/223424-remove-selected-item-from-dropdown-list-from-query/ 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"); Link to comment https://forums.phpfreaks.com/topic/223424-remove-selected-item-from-dropdown-list-from-query/#findComment-1156872 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.