1, the Connection database query data display in the page
2. Submit the primary key value that needs to change the data to the processing page
3, the processing page through the primary key value to find the value of the Count column in the data, the value of the Count column and 1 copied to the Count column
4. An explicit result on another page
You can copy and paste the run:
Database tables
Result diagram:
Main Page
<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
<body>
<?php
Include ("DBDA.class.php");
$db = new Dbda ();
$sql = "SELECT * from Diaoyantimu";
$tm = $db->query ($sql);
$sql = "SELECT * from Diaoyanxuanxiang where Timudaihao = ' {$tm [0][0]} '";
$xx = $db->query ($sql);
echo "<div style=\" width:100%; Text-align:center;\ ">";
echo "
?>
<form action= "tianjia.php" method= "POST" >
<table width= "150px" style= "margin:0 auto; Text-align:left; ">
<?php
foreach ($xx as $v) {
echo "<tr>
<td><input type=\ "checkbox\" name=\ "xx[]\" value=\ "$v [0] \"/> $v [1] </td>
</tr> ";
}
?>
</table>
<div><input type= "Submit" value= "Submission"/>
<a href= "jieguo.php" ><input type= "button" value= "View Results"/></a></div>
</form>
</div>
<div style= "width:100%; Text-align:center; " >
<form action= "tianjia1.php" method= "POST" >
<table width= "300px" style= "margin:0 auto; Text-align:left; ">
<?php
$sql = "SELECT * from Diaoyanxuanxiang where Timudaihao = ' {$tm [1][0]} '";
$xx = $db->query ($sql);
foreach ($xx as $v) {
echo "<tr>
<td><input type=\ "radio\" name=\ "xx\" value=\ "$v [0] \"/> $v [1] </td>
</tr> ";
}
?>
</table>
<div><input type= "Submit" value= "Submission"/>
<a href= "jieguo.php" ><input type= "button" value= "View Results"/></a></div>
</form>
</div>
</body>
Processing page:
<?php
Include ("DBDA.class.php");
$xx = $_post["xx"];
$db = new Dbda ();
Var_dump ($XX);
foreach ($xx as $v) {
$sql = "Select numbers from Diaoyanxuanxiang where ids = {$v}";
$num = $db->query ($sql);
Var_dump ($num);
$sql = "Update Diaoyanxuanxiang Set numbers = ({$num [0][0]}+1) where ids = {$v}";
if (! $db->query ($sql, 0)) {
echo "Add Error";
}
}
Header ("location:toupiao.php");
Show Results page
<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
<meta http-equiv= "Content-type" content= "text/html; Charset=utf-8 "/>
<title> Untitled Document </title>
<body>
<?php
Include ("DBDA.class.php");
$db = new Dbda ();
$sql = "SELECT * from Diaoyantimu";
$tm = $db->query ($sql);
$sql = "SELECT * from Diaoyanxuanxiang where Timudaihao = ' {$tm [0][0]} '";
$xx = $db->query ($sql);
$sql = "Select sum (Numbers) from Diaoyanxuanxiang where Timudaihao = ' {$tm [0][0]} '";
$sum = $db->query ($sql);
echo "<div style=\" width:100%; Text-align:center;\ ">";
echo "?>
<table width= "400px" style= "margin:0 auto; Text-align:left, "cellpadding=" 0 "cellspacing=" 0 ">
<?php
foreach ($xx as $v) {
$ba = Floor (($v [2]/$sum [0][0]) *10000);
$BB = $BA/100;
echo "<tr>
<td>{$v [1]}</td>
<td>
<div style=\ "height:10px; width:150px; border:1px solid #000; \ ">
<div style=\ "height:10px; Width: $bb%; Background-color: #F00 \ "></div>
</div>
</td>
<td>{$v [2]}</td>
<td> ($bb%) </td>
</tr> ";
}
?>
</table>
<?php
echo "$sql = "SELECT * from Diaoyanxuanxiang where Timudaihao = ' {$tm [1][0]} '";
$xx = $db->query ($sql);
$sql = "Select sum (Numbers) from Diaoyanxuanxiang where Timudaihao = ' {$tm [1][0]} '";
$sum = $db->query ($sql);
?>
<table width= "400px" style= "margin:0 auto; Text-align:left, "cellpadding=" 0 "cellspacing=" 0 ">
<?php
foreach ($xx as $v) {
$ba = Floor (($v [2]/$sum [0][0]) *10000);
$BB = $BA/100;
echo "<tr>
<td>{$v [1]}</td>
<td>
<div style=\ "height:10px; width:150px; border:1px solid #000; \ ">
<div style=\ "height:10px; Width: $bb%; Background-color: #F00 \ "></div>
</div>
</td>
<td>{$v [2]}</td>
<td> ($bb%) </td>
</tr> ";
}
?>
</table>
</div>
<div style= "width:100%; Text-align:center; " >
<a href= "toupiao.php" ><input type= "button" value= "Back"/></a></div>
</body>
PHP Voting exercises