我创建了一个名为<?php
require("connection.inc.php");
$query = "SELECT SUM(john), SUM(robert), COUNT(school) FROM election";
$result = mysql_db_query($db, $query, $connection) or
die("query error!");
$data = mysql_fetch_array($result);
$john = number_format($data[0], 0,',','.');
$robert = number_format($data[1], 0,',','.');
$school = $data[2];
$total = $john + $robert;
$remaining_school = 524 - $school;
$percentage_john = round(($john*100/$total),2);
$percentage_robert = round(($robert*100/$total),2);
?>
display.php
然后我在display.php
中显示数据
数据显示良好,没有任何错误,我尝试了几个技巧,使用jquery自动刷新容器但失败了。
这是我的<?php
include("queries.php");
?>
<div id="totaljohn"> // <--- the div id taken from css layout
<h9>John: <?php echo $john; ?> <br> (<?php echo $percentage_john; ?> %)</h9>
</div>
<div id="totalrobert">
<h9>Robert: <?php echo $robert; ?><br> (<?php echo $percentage_robert; ?> %)</h9>
</div>
<div id="totalboth">
<h4>Total : <?php echo $total; ?> Suara</h4>
</div>
<div id="totalschool">
<h4>Total School attending : <?php echo $school; ?> Schools</h4>
</div>
<div id="remaining_schools">
<h4>Remaining Schools: <?php echo $remaining_school; ?> of 524 schools</h4>
</div>
页面:
def menu():
print("MENU")
print("1) Test")
print("2) Quit")
choice = int(input("\nChoose an option : "))
return choice
while choice != 2 :
choice = menu()
if choice == 1 :
do_this
elif choice == 2 :
print("This program will terminate.")
break
else :
print("Invalid option... ")
答案 0 :(得分:2)
一切看起来都不错。你的数据库是否连接?你的SQL是正确的吗?是否为您的查询返回了数据库中的记录?