-2
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>";
}
?>

目前这是在页面下方创建表格。我想知道是否有办法让两张桌子并排:

表 1 表 2
表 3 表 4
表 5 表 6

或者如果它们适合页面,甚至可能是 3 个。

表 1 表 2 表 3
表 4 表 5 表 6

4

2 回答 2

1

在页面头部添加:

<script type="text/css">
  table{
    width: 30%;
    margin: 2%; 
    float: left;
  }
</script>

您可能不得不玩弄边距,或者您可能根本不需要它们,但这应该让 3 张桌子彼此相邻

于 2013-11-08T17:40:12.813 回答
1

将结果包装在另一个表中。

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>";
于 2013-11-08T17:55:38.783 回答