getseats.php包含回報,如果座位的狀態爲0,則可點擊圖標應該變爲不可用,難以實現!任何幫助或建議將不勝感激!香港專業教育學院下面所示我的代碼:根據數據庫在頁面上改變圖像
<?php
$noerrors=dbconnect();
if($noerrors <> 0) {
echo '{"errorcode":"'.$noerrors.'"}';
} else {
$query = "select seatnum from seats where status='0'";
$link = mysql_query($query);
if (!$link) {
echo '{"errorcode":"3"}';
} else {
$rows = array();
while($r = mysql_fetch_assoc($link)) {
$rows[] = $r;
}
$json=json_encode($rows);
echo $json;
}
}
function dbconnect(){
$hostname = "localhost";
$username = "root";
$password = "root";
$noerrors = 0;
$link = @ mysql_connect($hostname, $username, $password);
if (!$link) {
$noerrors = 1;
} else {
$db_selected = @ mysql_select_db('bookings', $link);
if (!$db_selected) {
$noerrors = 2;
}
}
return $noerrors;
}
我也有一個JavaScript文件(booking.js)將包含在HTML腳本中提到的功能,但不包含代碼爲套牢部分IM。以下是第一行的HTML。
HTML:
<div id='right' style='float:right; margin-top:2%;margin-right:15%'>
<div style="">
<table style="align:center">
<tr>
<td ColSpan="7">A </td>
<td><img id = "A1" src="images/available.gif" style="border:none" onmouseover="over(this)" onmouseout="out(this)" onclick="sold(this.id)" /></td>
<td><img id = "A2" src="images/available.gif" style="border:none" onmouseover="over(this)" onmouseout="out(this)" onclick="sold(this.id)" /></td>
<td><img id = "A3" src="images/available.gif" style="border:none" onmouseover="over(this)" onmouseout="out(this)" onclick="sold(this)" /></td>
<td><img id = "A4" src="images/available.gif" style="border:none" onmouseover="over(this)" onmouseout="out(this)" onclick="sold(this)" /></td>
<td><img id = "A5" src="images/available.gif" style="border:none" onmouseover="over(this)" onmouseout="out(this)" onclick="sold(this)" /></td>
<td><img id = "A6" src="images/available.gif" style="border:none" onmouseover="over(this)" onmouseout="out(this)" onclick="sold(this)" /></td>
<td ColSpan="6"></td>
</tr>
我如何實現圖像從根據使用JSON回報AJAX請求 'available.gif' 到 'taken.gif' 而改變。
注意:你不應該再使用mysql_'了。 – JiFus 2014-10-17 09:34:15