下面是我的选择标记代码。我需要在temp变量中选择输入。
并使用此变量进行搜索。
FOR EX -
<select>
<option value="volvo">Volvo</option>
<option value="saab">Saab</option>
<option value="vw">VW</option>
<option value="audi" selected>Audi</option>
</select>
现在我从列表框中选择了Saab。然后在temp中的变量中得到这个值 并在搜索查询中使用此临时变量。
<?php
$temp = "Saab";
$book_no2 = $temp;
$receipt = $database->getRows("SELECT receipt_no FROM scheme_master WHERE book_no2 = :book_no2", array(':book_no2'=>$book_no2));
?>
<select name="book" onChange="showUser(this.value)">
<?php foreach ($book as $load_book){ ?>
<option value=""></option>
<option value="<?php echo $load_book["book_no"]; ?>"><?php echo $load_book["book_no"]; ?></option>
<?php }?>
</select>
<?php
$book_no2 = $load_book["book_no"];
$receipt = $database->getRows("SELECT receipt_no FROM scheme_master WHERE book_no2 = :book_no2", array(':book_no2'=>$book_no2));
?>
答案 0 :(得分:0)
您应该从全局$_POST
变量中形成并获取所选书籍,但请确保正确转义来自客户端的所有变量(例如,使用mysql_real_escape_string PHP函数)。
<?php
$book_no2 = mysql_real_escape_string($_POST['book']);
$receipt = $database->getRows("SELECT receipt_no FROM scheme_master WHERE book_no2 = :book_no2", array(':book_no2'=>$book_no2));
?>
<form method="POST">
<select name="book" onChange="showUser(this.value)">
<?php foreach ($book as $load_book){ ?>
<option value=""></option>
<option value="<?php echo $load_book["book_no"]; ?>"<?php if ($load_book["book_no"] == $temp):?> selected="selected"<?php endif?>><?php echo $load_book["book_no"]; ?></option>
<?php }?>
</select>
<input type="submit" value="Send" />
</form>
答案 1 :(得分:0)
Plz看到......这将解决我的问题......
<select name="book" onChange="showUser(this.value)">
<option value="<?php if(isset($_GET['edit'])){ echo $data['book']; }?>"><?php if(isset($_GET['edit'])){echo $data['book'];}?></option>
<?php foreach ($book as $load_book){ ?>
<option value=""></option>
<option value="<?php echo $load_book["book_no"]; ?>"><?php echo $load_book["book_no"]; ?></option>
<?php }?>
</select>
<?php
$book_no2 = $load_book["book_no"];
$receipt = $database->getRows("SELECT DISTINCT receipt_no FROM scheme_master WHERE book_no2 = :book_no2", array(':book_no2'=>$book_no2));
?>
答案 2 :(得分:0)
制作您的第一个文件
<form action="second page" method="post"
<select name="car">
<option value="volvo">Volvo</option>
<option value="saab">Saab</option>
<option value="vw">VW</option>
<option value="audi" selected>Audi</ option>
</select>
<input type="submit">
</form>
然后将其传递给你的temp var
$temp=$_POST[`car`];