我正在编写一个迷你网络项目来了解php / html / java。我编码的页面包含一个使用php代码的表。这个PHP代码允许我连接到我的数据库并获取我想在表中显示的值。然后我有一个选择框返回所选字段的值(通过javascript?)。必须使用此值刷新php表。所以必须将值发送到php代码(通过Ajax?)并刷新我对我的数据库的查询,以便表格显示新的值。这是我现在的情况:
<html>
<head>
<title>Test</title>
<style type="text/css">
body {
background-color: #9C3;
}
p {color:black;}
.table_test {
font-family: Constantia, Lucida Bright, DejaVu Serif, Georgia, serif;
}
</style>
</head>
<body><div align='center'>
<p> </p>
<p>test!</p>
<p> </p>
<div class="table_test">
<table border='1' cellpadding='0' cellspacing='0' width='600' bgcolor='#F6F6F6' bordercolor='#FFFFFF'>
<tr>
<td width='150' style='font-weight: bold'></td>
<td width='150' style='font-weight: bold'>Festa</td>
<td width='150' style='font-weight: bold'>Preu</td>
<td width='150' style='font-weight: bold'>Entrada</td>
<td width='150' style='font-weight: bold'>Final</td>
<td width='150' style='font-weight: bold'>Estil</td>
<td width='150' style='font-weight: bold'>Llista</td>
</tr>
<?php
include ('connection.php');
include ('functions.php');
$dw = date("w");
echo "Avui es el dia: $dw";
$query = 'SELECT disco_id, party_name, price, hin, hout, style, list FROM disco_var WHERE day = '.$dw;
$result = mysql_query($query,$connect);
while ($reg = mysql_fetch_array($result))
{
$disco_id = $reg['disco_id'];
$disco_name = get_disco_name_from_id($disco_id);
$hin = substr($reg['hin'],0,5);
$hout = substr($reg['hout'],0,5);
$price = $reg['price'];
if ($reg['list'] == 1) $list = "Apunta't!";
else $list = "-";
echo "<tr>
<td width='150'>".$disco_name."</td>
<td width='150'>".$reg['party_name']."</td>
<td width='150'>".$reg['price']." e</td>
<td width='150'>".$hin."</td>
<td width='150'>".$hout."</td>
<td width='150'>".$reg['style']."</td>
<td width='150'>".$list."</td>
</tr>";
}
include ('close_connection.php');
?>
</table>
</div>
<p>Veure un altre dia de la setmana:
<select name="day_select" id="day_select" onchange="dayChanged(this);">
<option value="1">Dilluns</option>
<option value="2">Dimarts</option>
<option value="3">Dimeces</option>
<option value="4">Dijous</option>
<option value="5">Divendres</option>
<option value="6">Dissabte</option>
<option value="0">Diumenge</option>
</select>
</p>
<script type="text/javascript"> //Here is the problem!!
function dayChanged(opt)
{
//What should be the code here?
}
</script>
</body>
</html>
所以我希望php $ dw中的de var能够通过选择框(onClick函数)中选择的选项的值进行刷新。那么另一个问题是如何用这个$ dw值刷新表。
我是php / html / java编码的新手,我真的很喜欢它。谢谢。