我有一个很好的Chain SELECT,但是我希望能够将数据从搜索记录表单推送到包含Chain SELECT的表单,我怎么可能在这个中使用SELECTED = SELECTED码?
我的select.class.php
<?php
class SelectList {
public function ShowMake($searchboilermake) {
include "./core/cnn.php";
$sql = "SELECT * FROM blr_boilermake";
$res = mysql_query($sql);
$boilermake = '<option value=""></option>';
while($row = mysql_fetch_array($res)) {
$boilermake .= '<option value="' . $row['BoilerID'] . '"';
$boilermake .= ($row['BoilerID']==$searchboilermake) ? " selected='selected' " : "";
$boilermake .= '>' . $row['BoilerMake'] . '</option>';
}
return $boilermake;
}
public function ShowModel() {
include "../core/cnn.php";
$sql = "SELECT * FROM blr_boilermodel WHERE BoilerModel IS NOT NULL AND BoilerID = $_POST[id]";
$res = mysql_query($sql);
$boilermodel = '<option value="0"></option>';
while($row = mysql_fetch_array($res)) {
$boilermodel .= '<option value="' . $row['ModelID'] . '">' . $row['BoilerModel'] . '</option>';
}
return $boilermodel;
}
}
$opt = new SelectList();
?>
从我在我页面上的表单中我使用它来引入select.class.php以获取boilermake字段
<label>Manufacturer</label>
<select class="select2_category form-control" data-placeholder="Choose a Category" tabindex="1" id="boilermanufacturer" name="boilermanufacturer">
<?php echo $opt->ShowMake($_REQUEST['boilermanufacturer']); ?>
</select>
这是我的boilermodel字段
<label>Model</label>
<select class="select2_category form-control" data-placeholder="Choose a Category" tabindex="1" id="boilermodel" name="boilermodel">
<option value=""></option>
</select>
在其他更直接和标准SELECT的SELECTS中,我使用下面的内容,但我如何在下面对我的Chain SELECT进行调整?
<div class="form-group">
<label>Fuel Type</label>
<?php $fueltype = db::getInstance()->query('SELECT * FROM lkup_fueltype');
if(!$fueltype->count()) {
echo 'Problem';
} else { ?>
<select class="select2_category form-control" data-placeholder="Choose a Category" tabindex="1" id="propertyfueltype" name="propertyfueltype">
<?php foreach ($fueltype->results() as $fueltype) { ?>
<option value="<?php echo $fueltype->ID; ?>"<?php echo $fueltype->ID == $searchboilerfueltype ? "selected" : ""; ?>><?php echo $fueltype->PropertyFuelType; ?></option> <?php } } ?>
</select>
我尝试使用它,但在运行代码时没有选择SELECTED行
$boilermake .= '<option value="' . $row['BoilerID'] . '" "' . $row['BoilerID'] . '" == $searchboilermake ? "selected" : "">' . $row['BoilerMake'] . '</option>';
我应该做些什么/或者我该怎么做才能让它发挥作用?
答案 0 :(得分:0)
问题是你试图在字符串中使用boolean / ternary表达式。这显然不会用这样的字符串进行评估。
$boilermake .= '<option value="' . $row['BoilerID'] . '"';
$boilermake .= ($row['BoilerID']==$searchboilermake) ? " selected='selected' " : "";
$boilermake .= '>' . $row['BoilerMake'] . '</option>';
修改:您需要修复函数ShowMake
以传递$searchboilermake
作为参数。
功能定义:
public function ShowMake($searchboilermake) {
致电功能:
<?php echo $opt->ShowMake($_REQUEST['boilermanufacturer']); ?>