include "./tp.class.php";
$db = new TP();
$sql = "select * from tpz where Ids = 1";
$attr = $db->Query($sql);
?>
$sql1 = "select Idr,options from tp";
$attr1 = $db->Query($sql1);
foreach($attr1 as $v)
{
echo "".$v[1]."
";
}
?>
$sql1 = "select * from tp where Timudaihao = 1";
$attr1 = $db->Query($sql1);
$sql2 = "select sum(numbers) from tp";
$c = $db->Query($sql2);
foreach($attr1 as $v)
{
$b = $v[2]/$c[0][0]*100;
$b1 = number_format($b,2);
echo "
{$v[1]} | {$v[2]} ({$b1}%) |
}
?>
处理:
include "tp.class.php";
$db = new TP();
$tp = $_POST["tp"];
if(!empty($tp))
{
foreach ($tp as $v)
{
$sql1 = "select numbers from tp where Idr= {$v[0]}";
$b1 = $db->Query($sql1);
$b2 = $b1[0][0]+1;
$sql = "update tp set numbers={$b2} where Idr = {$v[0]}";
$a = $db->Query($sql,1);
}
if($a)
{
header("location:main.php");
}
else
{
echo "失败!";
}
}
else
{
header("location:main.php");
}
类:
class TP
{
public $host = "localhost";
public $uid = "root";
public $pwd = "";
public function Query($sql,$type=0,$db="news")
{
$d = new MySQLi($this->host,$this->uid,$this->pwd,$db);
!mysqli_connect_error() or die("连接失败!");
$result = $d->query($sql);
if($type==0)
{
return $result->fetch_all();
}
else
{
return $result;
}
}
}