PHP? ??? ?? ??? ?? ??? ?? ??? ?????(2)
?? ??? ??? ? ?? ??? ???? ? ????? ? ?? ?? ?? ????? ???? ? ? ????.
"?? ??"? ???? ????? ???? ? ??? ?? ?? ??? ?????.
<input type="hidden"> ??? ?? ?? ??
<input type="hidden"> ??? ??? ????? ????? ???? ????. ??? ???? ?????? ??? ??? ????. ??? ?? ??? ???? ??? ???? ??? ?? ??? ??? ?????.
hidden ??? ???? ?? ??? ??? ???(?: ??? ??) ???? ??? ? ? ??? ? ?? ????. ?? ?? JavaScript? ??? ??? ???? ? ??? ??? ? ????.
<input type="hidden" id="selected_id" name="selected_id" value=""> <input type="button" value="查看結(jié)果" onClick="location.href='index.php?id=ck'"/> <script type="text/javascript"> $("[type='radio']").click(function(){ $("#selected_id").val($(this).val()); }); </script>
??? ?? ?? ???? ???? ?? ??? ?????.
<?php $id=$_POST["itm"]; $SQL="UPDATE vote SET count=count+1 WHERE id=$id"; //自動添加投票數(shù) if(mysqli_query($link,$sql)) { $_SESSION["vote"]=session_id(); ?> <script language="javascript">alert("投票成功,點確定查看結(jié)果");location.href="index.php?id=ck";</script> <?php } else { ?> <script language="javascript">alert("投票失敗");location.href="index.php";</script> <?php } ?>
??? <table> ???? ?? ?? ??? ?????.
? ?? ?? ?? ???? ?? ??? sum()? ?? ??????? ???? ??? ?? ?? ? ??
<?php if(isset($_GET["id"])=="ck"){ ?> <?php $SQL="SELECT sum(count) as 'total' FROM vote"; $rs=mysqli_query($link,$sql); $rows=mysqli_fetch_assoc($rs); $sum=$rows["total"]; //得出總票數(shù) } ?>
? ??? ? ??? ?? ? ?? ??? ???? SQL ? SELECT? ???? ?? ???? ?? ?? ?????. ?????? ???? ??? ?? ?? ? ?? ?? ????.
????