请大家帮帮我。-6ren">
gpt4 book ai didi

php - 算公务舱 同等值(value)

转载 作者:行者123 更新时间:2023-11-29 08:06:04 24 4
gpt4 key购买 nike

<?php
$con = mysql_connect("localhost","root","root");
if (!$con){
die("Can not connect: " . mysql_error());
}
mysql_select_db("mydb",$con);

//Count all Total of Acc Class with same value Example Restaurant, Hotel
$query = "select acc_class,count(*) as total from mytable group by acc_class";
$result = mysql_query($query);
$values = mysql_fetch_assoc($result);
$num_total = $values['total'];

while($record = mysql_fetch_array($result)){
echo '<br>';
echo "<label>" . $record['acc_class'] . "</label>";
echo "<label>" . $num_total . "</label>";
}

mysql_close($con);
?>

请大家帮帮我。我想制作这样的东西。但我不知道怎么办。

Account Class   Total
------------- -----------
Hotel 5
Restaurant 2
Club 3
Church 1

我想要一个页面,其中将显示每个帐户类别的总数。请帮忙。

谢谢!

最佳答案

//you just need to put the name of the column in quert like COUNT(column_name)


$con = mysql_connect("localhost","root","root");
if (!$con){
die("Can not connect: " . mysql_error());
}
mysql_select_db("mydb",$con);
//data base connection ends here

//you write a query to fire if you want by order the put "ORDER BY HERE"
$query = "select acc_class,count(acc_class) as total from mytable group by acc_class";



//here you fire a query to mysql
$result = mysql_query($query);


//now put the selected roe in loop and again and again loop ask for more data to mysql
while($record = mysql_fetch_array($result)){

**//here you select all the group in the table**

echo '<br>';
echo "<label>" . $record['acc_class'] . "</label>";
echo "<label>" . $record['total'] . "</label>";


}

//close connection to database
mysql_close($con);

关于php - 算公务舱 同等值(value),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22729778/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com