In this section, there is a book statistics column "Book Statistics" function page in the menu management bar.
Use this page to classify and count all books, as shown in the figure
html uses <table> table, which uses <tr><td> layout, plus css style.
<table width="100%" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#CCCCCC" class="table"> <tr> <td height="27" colspan="2" align="left" bgcolor="#FFFFFF" class="bg_tr"> 后台管理 >> 图书统计</td> </tr> <tr> <td align="center" bgcolor="#FFFFFF" height="27">图书类别</td> <td align="center" bgcolor="#FFFFFF">库内图书</td> </tr> </table>
The content is displayed through SQL statement query
The COUNT(*) function is used here to return the number of records in the table.
When using the GROUP BY statement, it is used in combination with the total function to group the result set based on one or more columns.
Use group by to group type.
<?php $SQL = "SELECT type, count(*) FROM yx_books group by type"; ?>
Finally use a while loop to retrieve the data queried from the database
<?php $SQL = "SELECT type, count(*) FROM yx_books group by type"; $val=mysqli_query($link,$sql); while($arr=mysqli_fetch_row($val)){ echo "<tr height='30'>"; echo "<td align='center' bgcolor='#FFFFFF'>".$arr[0]."</td>"; echo "<td align='center' bgcolor='#FFFFFF'>本类目共有:".$arr[1]." 种</td>"; echo "</tr>"; } ?>
Note:
The mysql_fetch_row() function obtains a row from the result set as a numeric array.
Return value: Returns the array generated based on the rows obtained, or returns false if there are no more rows.