将表并排设置,而不是在进行while循环时将表向下对齐 [英] Set tables as side by side instead of straight down while doing a while-loop
本文介绍了将表并排设置,而不是在进行while循环时将表向下对齐的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
include 'inc.php';
$varVeh=$_POST['Veh_num'];
$sql_course="select course_num from hc_course";
$results_course=mysql_query($sql_course);
$sql_vehName="select Veh_name from hc_vehicle_type where Veh_num=$varVeh ";
$result_vehName = mysql_query($sql_vehName);
$vehName=mysql_fetch_assoc($result_vehName);
echo "<table><tr><th>Best Scores for".$vehName['Veh_name']."</th> </tr></table>";
while($rc = mysql_fetch_array($results_course)){
$sql_HiScores = "SELECT c.course_name as course, e.distance as distance, e.score as score, e.time as time, e.user as User from hc_entries e left join hc_course c on e.course=c.course_num WHERE c.course_num=".$rc['course_num']." and e.vehicle=$varVeh ORDER BY course, score DESC Limit 3 ";
$result_HiScores = mysql_query($sql_HiScores);
?>
<table border='1'>
<tr>
<th>Course</th>
<th>Score</th>
<th>Distance</th>
<th>Player</th>
<th>Time</th>
</tr>
<?php
while($row = mysql_fetch_array($result_HiScores))
{
echo "<tr>";
echo "<td>" .$row['course'] . "</td>";
echo "<td>" .$row['score'] . "</td>";
echo "<td>" .$row['distance'] . "</td>";
echo "<td>" .$row['User'] . "</td>";
echo "</tr>";
}
echo "</table>";
}
?>
当前,这是在页面下方创建表.我想知道是否有一种方法可以并排放置2张桌子:
Currently this is creating tables down the page. I was wondering if there is a way of getting 2 tables side by side :
表1表2
表3表4
表5表6
Table 1 Table 2
Table 3 Table 4
Table 5 Table 6
甚至可以容纳3个,如果它们适合页面.
Or maybe even 3 if they will fit on the page.
表1表2表3
表4表5表6
Table 1 Table 2 Table 3
Table 4 Table 5 Table 6
推荐答案
将结果包装到另一个表中.
echo "<table>";
$count = 0;
$num_columns = 2; // or 3
while ($rc = mysql_fetch_array($results_course)) {
if ($count++ % $num_columns == 0) {
echo "<tr>";
}
echo "<td>";
// previous table code here
echo "</td>";
if ($count % $num_columns == 0) {
echo "</tr>";
}
}
if ($count % $num_columns > 0) {
echo "</tr>";
}
echo "</table>";
这篇关于将表并排设置,而不是在进行while循环时将表向下对齐的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文