我之前已经问过这个问题,但所有建议的解决方案都不起作用,所以我想改写它,我有一个html用户输入字段,它将数据发布到表单代码;
#include <iostream>
#include <cstdlib>
using namespace std;
#include "QueueInt.h"
// Add an integer to the back of the queue.
void QueueInt::enqueue(int val)
{
queueObj.push(val);
}
// Removes and returns an integer from the front of the queue. Aborts the
// program is the queue is empty.
int QueueInt::dequeue()
{
int val = front();
queueObj.pop();
return val;
}
// Returns but does not remove the integer at the front of the queue. Aborts the
// program is the queue is empty.
int QueueInt::front() const
{
if (isEmpty()) {
cerr << "Tried to access empty queue --> aborting program" << endl;
exit(-1);
}
return queueObj.front();
}
// Returns true if the queue is empty.
bool QueueInt::isEmpty() const
{
return queueObj.empty();
}
然后存储在变量中,此变量用于选择并将DB的结果回显到select标记 代码;
<form method="post" action="value1.php">
<input id="nol" style="width: 350px;" type="text" name="searchdisease" placeholder="type diagnosis one">
<input class="btn btn-success" style="width: 120px; margin-right: -90%; margin-left: 9%;" type="submit" name="search" value="Search">
</form>
所以我想在用户输入为空时禁用上面的下拉列表
像:
<?php
$search_disease = $_POST['searchdisease'];
$query="SELECT diagnosis, ICD10 FROM medications WHERE diagnosis LIKE '%$search_disease%'";
$result= $con->query($query);
?>
<select id="disease" style="width: 40%; position: relative;top: 220px; left: 182px; " name="tdisease">
<option value="">Select Disease</option>
<?php while ($row=$result->fetch_array(MYSQLI_ASSOC)) { ?>
<option value="<?php echo $row['ICD10']?>"><?php echo $row['diagnosis'];?> </option>
<?php } ?>
</select>
但我不知道我可以在if语句中使用哪些代码
答案 0 :(得分:0)
Try this once...
if($search_disease!=''){
?>
<select id="disease" style="width: 40%; position: relative;top: 220px; left: 182px; " name="tdisease">
<option value="">Select Disease</option>
<?php while ($row=$result->fetch_array(MYSQLI_ASSOC)) { ?>
<option value="<?php echo $row['ICD10']?>"><?php echo $row['diagnosis'];?> </option>
<?php } ?>
</select>
<?php } else { ?>
<select id="disease" style="width: 40%; position: relative;top: 220px; left: 182px; " name="tdisease" disable>
<option value="">Select Disease</option>
<?php while ($row=$result->fetch_array(MYSQLI_ASSOC)) { ?>
<option value="<?php echo $row['ICD10']?>"><?php echo $row['diagnosis'];?> </option>
<?php } ?>
</select>
<?php } ?>
答案 1 :(得分:0)
html设置了一个不可见的部分:
<input type="hidden" id="aaa" value="$search_disease">
JS:
<script type="text/javascript">
window.onload=function(){
var i = document.getElementById("aaa").value;
if (i==''){
document.getElementById("disease").style.display="none";
}
}