PHP部份
<?php
require_once('../Connections/con_Set.php');
foreach($_GET AS $key => $value) { $_GET[$key] = mysql_real_escape_string($value); }
$sql = <<<sql
SELECT dr.name, dr.did, ci.license, ci.car_category, dr.phone, com.name AS com_name, ci.brand, ci.cc
FROM tr_car_inf ci, tr_driver dr, tr_company com
WHERE ci.cid = com.cid
AND ci.did = dr.did
sql;
if ($_GET['driver']!=null) $sql .= "AND `dr`.`name` LIKE '%{$_GET['driver']}%' ";
if ($_GET['license']!=null) $sql .= "AND `ci`.`license` LIKE '%{$_GET['license']}%' ";
if ($_GET['phone']!=null) $sql .= "AND `dr`.`phone` LIKE '%{$_GET['phone']}%' ";
if ($_GET['com_name']!=null) $sql .= "AND `com`.`name` LIKE '%{$_GET['com_name']}%' ";
if ($_GET['car_category']!=null) $sql .= "AND `ci`.`car_category` LIKE '%{$_GET['car_category']}%' ";
if ($_GET['brand']!=null) $sql .= "AND `ci`.`brand` LIKE '%{$_GET['brand']}%' ";
if ($_GET['cc']!=null) $sql .= "AND `ci`.`cc` LIKE '%{$_GET['cc']}%' ";
$sql .=<<<sql
ORDER BY `dr`.`name` ASC
sql;
//echo $sql;
$data_array = array();
$result = mysql_query($sql) or trigger_error(mysql_error());
while($row = mysql_fetch_array($result)){
$data_array[] = array
(
"driver" => $row['name'],
"license" => $row['license'],
"phone" => $row['phone'],
"com_name" => $row['com_name'],
"car_category" => $row['car_category'],
"brand" => $row['brand'],
"cc" => $row['cc']
);
}
echo json_encode($data_array);
PHP讀取頁
echo <<<html
<script type="text/javascript">
$().ready(function() {
$("input").blur(function(){
$("tr").remove(".db_list");
$("tr").remove(".s_list");
jQuery.event.trigger( "ajaxStop" );
var inputv = $("input[type=text]").serialize();
/*var req = $(this).attr("id");
var value = $(this).val();
alert (inputv);*/
$.ajax({
url: "$jsonurl?" + inputv,
type: "GET",
dataType: "json",
success: function(Ddata) {
var i = 0;
$.each(Ddata, function() {
$("table.driver_list").append("<tr class=\"s_list\">" +
"<td>" + (i+1) + "</td>" +
"<td>" + Ddata[i].driver + "</td>" +
"<td>" + Ddata[i].license + "</td>" +
"<td>" + Ddata[i].phone + "</td>" +
"<td>" + Ddata[i].com_name.substring(0,2) + "</td>" +
"<td>" + Ddata[i].car_category + "</td>" +
"<td>" + Ddata[i].brand + "</td>" +
"<td>" + Ddata[i].cc + "</td>" +
"<td><a href=\"$in_url?lic=" + Ddata[i].license + "\">編輯</a></td>" +
"</tr>");
i++;
});
},
Error: function() {
alert("ERROR!!!");
}
});
$("#loading").ajaxStart(function(){
$(this).show();
});
$("#loading").ajaxStop(function(){
$(this).hide();
});
})//keyup end
})
</script>
<table width="800" border="1">
<tr>
<td></td>
<td><input name="driver" type="text" id="driver" size="10"/></td>
<td><input name="license" type="text" id="license" size="10"/></td>
<td><input name="phone" type="text" id="phone" size="14"/></td>
<td><input name="com_name" type="text" id="com_name" size="6"/></td>
<td><input name="car_category" type="text" id="car_category" size="10"/></td>
<td><input name="brand" type="text" id="brand" size="12"/></td>
<td><input name="cc" type="text" id="cc" size="8"/></td>
<td></td>
</tr>
<tr id="head">
<td>編號</td>
<td>車主</td>
<td>牌照號碼</td>
<td>手機</td>
<td>車行</td>
<td>車種</td>
<td>廠牌</td>
<td>CC數</td>
<td>功能</td>
</tr>
<tr id="loading" style="display:none;text-align:center">
<td colspan="9"><img src="{$base_theme_url}images/load.gif" width="24" height="24" /></td>
</tr>
html;
留言列表