开发者

Assign and remove off drop down list

Eg: There's this 3 venue. A, B, C Users can allocate students into either this 3. and once allocated, it will be removed off the dropdown list thus user cannot add them in anymore thereafter leaving 'B' and 'C' available. How do i do that 开发者_C百科using query statements?


SELECT *
FROM venues
WHERE venues.id NOT IN (
  SELECT venue_id
  FROM students
  WHERE id=:studentid
)


PHP on form submission

//Store all possible options
$opts = array("a","b","c");

//Create array from selected option
$selected = array($_POST['selectMenu']);

//Use array_diff to remove selected from options array
$revisedOpts = array_diff($opts,$selected);

//At this point, you can use $revisedOpts to make an SQL query
....

HTML/php

<select name='selectMenu'><?php
//Echo out remaining options
foreach($revisedOpts as $v) {
  echo "<option>".$v."</option>";
}
?></select>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜