0
當用戶單擊橫幅廣告時,需要更新MySQL表中的hitcount字段。讓隨機廣告顯示腳本可以正常工作,但無法知道如何在點擊時更新表格。假設必須將ID傳遞給Ajax,但不知道如何處理它?代碼如下:PHP/MySQL OnClick更新MySQL
include 'connection.php';
$query = "select * from ads where adtype = 'small' and status = 'yes' ORDER BY RAND() LIMIT 3";
$result = mysql_query($query) or die(mysql_error());
$num_results = mysql_num_rows($result);
if ($num_results !="0")
{
for($i=0;$i<$num_results;$i++)
{
$row = mysql_fetch_array($result);
$client = htmlspecialchars(stripslashes($row['client']));
$link = htmlspecialchars(stripslashes($row['link']));
$filename = htmlspecialchars(stripslashes($row['filename']));
$id = $row['id'];
echo "<tr>";
echo "<td>";
echo '<a href="';
echo $link;
echo '"><img src="thimg/';
echo $filename;
echo '" alt="';
echo $client;
echo '"></a>';
echo "</td>";
echo "</tr>";
}
}
真棒 - 謝謝你的朋友! – John 2011-04-29 11:58:03