好的,我认为对于经验丰富的网络开发人员来说,我所拥有的非常简单。现在,这是我的辩论网站 State of Debate 的索引页面。从下面的代码中,你可以看到我有一个while循环来呼应每个辩论,它对应于mySQL数据库中的一个“did”。为了赞成/反对的目的,我需要做的是让每个“做了”通过循环。然后我会将它传递给“upvote.php”和“downvote.php”。
我尝试了一个 foreach 循环,虽然这可能是答案,但我只是没有找到它。我已经使用了 $_SESSION['did'] = $row['did'] 并且所做的只是将最后一个 did 传递给 PHP 页面。
任何帮助表示赞赏。请询问您是否需要更多信息。
<?php
$result = mysql_query("SELECT did,debatetitle FROM debates");
while($row = mysql_fetch_array($result))
{
echo "<tr>";
echo "<td><a href='/debatepage.php?did=" . $row['did'] . " '>" . $row['debatetitle'] . "</a></td>";
?>
<tr><td>
<a href="upvote.php" onClick="alert('You have given this item a thumbs up! You can change your vote, or leave it how it is.')"; onMouseOver="return changImage()" onMouseOut= "return changImageBack()" ><img
name="jsbutton2" src="Graphics/thumbs-up-unclicked.jpeg" width="75" height="75" border="0"
alt="javascript button"></a>
<script type="text/javascript">
function changImage()
{
document.images["jsbutton2"].src= "Graphics/thumbs-up.jpeg";
return true;
}
function changImageBack()
{
document.images["jsbutton2"].src = "Graphics/thumbs-up-unclicked.jpeg";
return true;
}
</script>
<a href="downvote.php" onClick="alert('You have given this item a thumbs down! You can change your vote, or leave it how it is.')"; onMouseOver="return changeImage()" onMouseOut= "return changeImageBack()" ><img
name="jsbutton1" src="Graphics/thumbs-down-unclicked.jpeg" width="75" height="75" border="0"
alt="javascript button"></a>
<script type="text/javascript">
function changeImage()
{
document.images["jsbutton1"].src= "Graphics/thumbs-down.jpeg";
return true;
}
function changeImageBack()
{
document.images["jsbutton1"].src = "Graphics/thumbs-down-unclicked.jpeg";
return true;
}
</script>
</tr></td>
<?php
echo "</tr>";
}
echo "</table>";