我想在选择列表框项目时显示数据。以前在网格视图中,所有数据都将存在。如果用户选择了一个选项,则只显示选项数据。怎么做Php。这是我的代码
<td width="5%" align="right"><b>School<b></td><td width="1%"><b>:</b></td><td width="5%" align="left">
<select name="school_id" id="school_id" class="list_box">
<option value="">Select School</option>
<?php
$school_sql=mysql_query("select * from tbl_school");
while($school=mysql_fetch_array($school_sql))
{
?>
<option value="<?php echo $school['school_id'];?>" <?php if(isset($workshop_fetch['school_id']) && ($workshop_fetch['school_id']==$school['school_id'])) { echo "selected='selected'"; } ?> ><?php echo $school['school_name'];?></option>
<?php } ?>
</select>
</td>
</tr>
<tr class="table_txt2">
<td width="7%">S.No</td>
<td width="20%">School</td>
<td width="10%">Payment Details</td>
<td width="20%">Payment Date</td>
<td width="13%">Amount</td>
<td width="10%">Due Date</td>
<td width="10%">Paid Date</td>
<td width="10%">Is Paid</td>
</tr>
<?php
$slno=0;
$payment_sql=mysql_query("select * from tbl_school_payments");
while($result=mysql_fetch_array($payment_sql))
{
$slno++;
?>
<tr <?php if($slno%2==1) echo "class='table_txt3'"; else echo "class='table_txt4'"; ?> id="row_<?php echo $result['payment_id']; ?>">
<td ><?php echo $slno;?></td>
<td >
<?php
$school_sql=mysql_query("select * from tbl_school where school_id='$result[school_id]'");
$school=mysql_fetch_array($school_sql);
echo ucwords($school['school_name']);
?>
</td>
//Here code for display data
<td ><?php echo $result['payment_details'];?></td>
<td ><?php echo $result['payment_date'];?></td>
<td ><?php echo $result['amount_paid'];?></td>
<td ><?php echo $result['due_date'];?></td>
<td ><?php echo $result['paid_date'];?></td>
<td ><?php echo $result['is_paid'];?></td>
<?php } ?>
</table>
答案 0 :(得分:0)
<td width="5%" align="right"><b>School<b></td><td width="1%"><b>:</b></td><td width="5%" align="left">
<select name="school_id" id="school_id" class="list_box">
<option value="">Select School</option>
<?php
$school_sql=mysql_query("select * from tbl_school");
while($school=mysql_fetch_array($school_sql))
{
?>
<option value="<?php echo $school['school_id'];?>" <?php if(isset($workshop_fetch['school_id']) && ($workshop_fetch['school_id']==$school['school_id'])) { echo "selected='selected'"; } ?> ><?php echo $school['school_name'];?></option>
<?php } ?>
</select>
</td>
</tr>
<tr class="table_txt2">
<td width="7%">S.No</td>
<td width="20%">School</td>
<td width="10%">Payment Details</td>
<td width="20%">Payment Date</td>
<td width="13%">Amount</td>
<td width="10%">Due Date</td>
<td width="10%">Paid Date</td>
<td width="10%">Is Paid</td>
</tr>
<?php
$slno=0;
$payment_sql=mysql_query("select * from tbl_school_payments");
while($result=mysql_fetch_array($payment_sql))
{
$slno++;
?>
<tr <?php if($slno%2==1) echo "class='table_txt3'"; else echo "class='table_txt4'"; ?> id="row_<?php echo $result['payment_id']; ?>">
<td ><?php echo $slno;?></td>
<td >
<?php
/*This IF block added
===================== */
if(isset($_GET['id']))
{
$query = "select * from tbl_school where school_id=".mysql_real_escape_string($_GET['id']);
}
else
{
$query = "select * from tbl_school where school_id='$result[school_id]'";
}
$school_sql=mysql_query($query);
$school=mysql_fetch_array($school_sql);
echo ucwords($school['school_name']);
?>
</td>
//Here code for display data
<td ><?php echo $result['payment_details'];?></td>
<td ><?php echo $result['payment_date'];?></td>
<td ><?php echo $result['amount_paid'];?></td>
<td ><?php echo $result['due_date'];?></td>
<td ><?php echo $result['paid_date'];?></td>
<td ><?php echo $result['is_paid'];?></td>
<?php } ?>
</table>
添加了脚本标记
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js"></script>
<script type="text/javascript">
jQuery(document).ready(function($) {
jQuery('#school_id').change(function(e){
selected = jQuery('#school_id').val();
window.location = window.location.pathname + '?id=' + selected;
});
});
基本上发生的是,当您选择school_id
时,jQuery change()
函数会触发并将选定的school_id
附加到当前网址并转到该网址。现在,URL具有id = school_id
值,PHP在执行查询之前会检查该值。如果有,则在其select语句中使用该值。
这是你需要的吗?