我想从下拉列表中显示多种选择的语言,但只显示一种
if(isset($_POST['search'])){
$getuser = $user->search($_SESSION['id'], $_POST);
}
<select class="selectpicker btn btn-outline-light mx-0" data-width="fit" name="lang[]" multiple="" >
<?php while($row = $getlang->fetch_assoc()):; ?>
<option value="<?php echo $row['lang_id']; ?>">
<?php echo $row['name']; ?>
<?php endwhile ?>
</option>
</select>
<?php
public function search($id,$data){
$lang_id= $_REQUEST['lang'];
foreach($data['lang'] as $value) {
$q = "SELECT * FROM (
SELECT user_table.fname,user_table.lname, languages.name,languages.lang_id
FROM interested
INNER JOIN user_table ON interested.u_id = user_table.id
INNER JOIN languages ON interested.lang_id = languages.lang_id
WHERE NOT user_table.id='$id'
) AS I WHERE I.lang_id='$value' ";
}
$result = $this->connection->query($q);
return $result;
}
答案 0 :(得分:2)
您可以尝试将 endwhile标签放在关闭选项标签之外。因此,您的选择选项将如下所示:
<select class="selectpicker btn btn-outline-light mx-0" data-width="fit" name="lang[]" multiple>
<?php while($row = $getlang->fetch_assoc()): ?>
<option value="<?php echo $row['lang_id']; ?>">
<?php echo $row['name']; ?>
</option>
<?php endwhile; ?>
</select>