你可以做這樣的事情:
<?php
$username = $_COOKIE['username'];
$sql = "SELECT * FROM QUESTIONS WHERE username ='$username'";
$result = mysql_query($sql) or die(mysql_error());
if (mysql_num_rows($result) > 0) {
//---------- new
if(isset($_GET['voteID']))
{
$viteID = (int) $_GET['voteID'];
// your update query
}
//--------
?>
<table width="50%" cellpadding="5" cellspacing="0" border="1">
<tr><td><b>Question ID</b></td><td><b>Question</b></td><td><b>Active/Inactive</b></td></tr>
<?php
$html = '';
while ($row = mysql_fetch_row($result)) {
$html .= '<tr>';
$html .= '<td>' . $row[0] . '</td>';
$html .= '<td>' . $row[1] . '</td>';
$activity = $row[3];
// ---- new
$html .= '<a href="'.$_SERVER['PHP_SELF'].'?id='.$row[0].'">Vote Up</a>';
//-------
//if active = 1, do the following
if ($activity == 1) {
$html .= '<td>' . '<a href=markAsInActive.php>Active</a>' . '</td>';
} else {
$html .= '<td>' . 'Inactive' . '</td>';
}
$html .='</tr>';
}
echo $html;
?>
</table>
<?php
}
?>
您應該存儲ID在一個隱藏的輸入值,如果你不想使用AJAX。 – 2013-05-10 22:24:05
@ Siamak.A.M,我如何獲得問題ID來存儲它?這就是我想要的。 – Wabbit 2013-05-10 22:37:02
什麼是QUESTIONS表格結構? – 2013-05-10 22:38:56