例を次に示します。クエリを実行する必要があります。
<?php
//Some pseudo data kinda as your receive it from your query
$datafromSql = array(
array('id'=>1,'date'=>1,'month'=>1,'year'=>2012,'theData'=>'This is some data when the user select 1/1/2012'),
array('id'=>2,'date'=>2,'month'=>2,'year'=>2012,'theData'=>'This is some data when the user select 2/2/2012'),
array('id'=>3,'date'=>3,'month'=>3,'year'=>2012,'theData'=>'This is some data when the user select 3/3/2012'),
);
//Super simple API to access the data
if($_SERVER['REQUEST_METHOD']=='POST' && isset($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) === 'xmlhttprequest'){
header('Content-Type: text/html');
//pseudo code, really you would just format your query result
$return=array();
foreach($datafromSql as $row){
//Select all from array which match select choice
if($row['date']==$_POST['day'] || $row['month']==$_POST['month'] || $row['year']==$_POST['year']){
$return[]=$row['theData'].'<br />';
}
}
//output, with a fancy horizontal rule
echo implode('<hr />',$return);
die;
}?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<script type="text/javascript" src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.7.2.min.js" charset="utf-8"></script>
<script type="text/javascript">
function update(){
$.post('./<?php echo basename(__FILE__)?>',
{
day: $("#day").val(),
month: $("#month").val(),
year: $("#year").val()
},
function(data) {
$('#result').replaceWith('<div id="result"><h1>The Result:</h1>'+ data +'</div>');
});
}
$(document).ready(function(){
update();
});
</script>
</head>
<body>
<form id="dateform" >
<p>Select Date:
<select size="1" name="day" id="day" onChange="update()">
<?php foreach(range(1,31) as $i){echo '<option value="'.$i.'">'.$i.'</option>';} ?>
</select>
<select size="1" name="month" id="month" onChange="update()">
<?php foreach(range(1,12) as $i){echo '<option value="'.$i.'">'.$i.'</option>';} ?>
</select>
<select size="1" name="year" id="year" onChange="update()">
<?php foreach(range(2008,2012) as $i){echo '<option value="'.$i.'">'.$i.'</option>';} ?>
</select>
</p>
</form>
<p id='result'></p>
</body>
</html>