[英]MySQL - How to show in multiple columns html table, single column of mysql table
I want to know how to show in my php file with html a table with multiple columns but in that columns show only a single column results from mysqli 我想知道如何在我的php文件中用html显示一个包含多列的表但是在该列中只显示了mysqli的一个列结果
What I have for now is: 我现在拥有的是:
<?php
include "dbinc.php";
$con=mysqli_connect($servername,$username,$password,$database);
$letramasculinos = mysqli_query($con,"SELECT nome FROM nomes WHERE nome LIKE '$_POST[letra]%' AND sexo = 'm';");
$letrafemininos = mysqli_query($con,"SELECT nome FROM nomes WHERE nome LIKE '$_POST[letra]%' AND sexo = 'f';");
(more code...)
echo "<table style='display: inline-block;' width='150px' border='1' bgcolor='#6699FF'>";
while($row = mysqli_fetch_array($letramasculinos))
{
echo "<tr>";
echo "<td><center>" . $row['nome'] . "</center></td>";
echo "</tr>";
echo " ";
echo "<table style='display: inline-block;' width='150px' border='1' bgcolor='#FF99FF'>";
while($row = mysqli_fetch_array($letrafemininos))
{
echo "<tr>";
echo "<td><center>" . $row['nome'] . "</center></td>";
echo "</tr>";
}
echo "</table>";
}
(more code...)
?>
In this example code this shows 2 HTML tables with 1 column but as entries are too much I want divide that column by 3 columns (or by 4 or 5, etc...) in each table. 在此示例代码中,这显示了2个包含1列的HTML表,但由于条目太多,我希望在每个表中将该列除以3列(或4或5,等等)。
How can I do this? 我怎样才能做到这一点?
Example: 例:
What I have and What I want 我拥有什么,我想要什么
I have this: I Want Something like this:
+---------+ +--------+---------+--------+
| Diogo | | Diogo | André | João |
+---------+ +--------+---------+--------+
| André | | Filipe | Carlos | Gaspar |
+---------+ +--------+---------+--------+
| João | | Fabio | Fernado | |
+---------+ +--------+---------+--------+
| Filipe |
+---------+
| Carlos |
+---------+
| Gaspar |
+---------+
| Fabio |
+---------+
| Fernado |
+---------+
I am not a php guy but some algo might help.1) get the count of records for male /female 我不是一个PHP人,但一些算法可能会帮助.1)得到男/女的记录数
"SELECT count(*)FROM nomes WHERE nome LIKE '$_POST[letra]%' AND sexo = 'f'; ..... same for 'male'.
save this to mcount and fcount variables. 将其保存到mcount和fcount变量。
if mcount >10
then
noOfColms=mcount /10;
i=0;
put "<table>"
loop records
i=i+1;
put "<tr>"
if(i<noOfColms)
put "<td>" + data +"</td>"
if i==noOfColms
put "</tr>"
end loop
put "</table>"
else show list view 否则显示列表视图
do same thing for fcount 为fcount做同样的事情
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.