在多个HTML表格中显示结果 [英] Display results in multiple html tables
问题描述
我一直在为我们的曲棍球俱乐部制作志愿者报名表.我使用while循环在表中显示结果.
I have been making a volunteer sign up sheet for our hockey club. I display the results in a table using a while loop.
一切正常,但是我现在想使输出更加用户友好.我按日期对查询进行排序并将其显示在单个表中.我想为每个不同的日期显示一个新表.该表的标题将是日期,并且行将按时间对该日期的所有事件进行排序.我认为这将使人们更容易找到特定日期的事件.
Everything works good, but I am now wanting to make the output a little more user friendly. I order the query by the date and display it in a single table. What I would like to do is display a new table for each different date. The heading of that table would be the date and the rows would have all events for that date ordered by time. I think this would make it easier for people to find events on a specific date.
这是我的表格的设置方式:id,日期,时间,游戏,name1,name2,name3,name4,name5
Here is how my table is set up: id, date, time, game, name1, name2, name3, name4, name5
这是我主页上的查询:
<?php
//displays the table
$result = mysql_query("SELECT * FROM namestable ORDER BY date, time ASC");
displayTable($result);
?>
这是我的功能:
<?php
function displayTable($result){
echo "
<table border='1'>
<tr class='top'>
<th class='date'>Date</th>
<th class='time'>Time</th>
<th class='game'>Game</th>
<th class='name'>Name</th>
<th class='name'>Name</th>
<th class='name'>Name</th>
<th class='name'>Name</th>
<th class='name'>Name</th>
<th class='sign'>Sign Up</th>
</tr>";
while($row = mysql_fetch_array($result))
{
//change the date format here
$fdate = date('M jS, Y l', strtotime($row['date']));
echo "<tr>";
echo "<td class='date'>" . $fdate . "</td>";
echo "<td class='time'>" . $row['time'] . "</td>";
echo "<td class='game'>" . $row['game'] . "</td>";
echo "<td class='nameA'>" . $row['name1'] . "</td>";
echo "<td class='nameB'>" . $row['name2'] . "</td>";
echo "<td class='nameA'>" . $row['name3'] . "</td>";
echo "<td class='nameB'>" . $row['name4'] . "</td>";
echo "<td class='nameA'>" . $row['name5'] . "</td>";
$id = $row['id'];
echo "<td class='sign'>" . "<form name='input' action='process.php' method='POST'>
<input type='text' name='name' maxlength='25' value='Enter Name' onfocus=\"if(this.value=='Enter Name') this.value='';\"/>
<input type='hidden' name='id' value='$id'/>
<input type='submit' value='Sign Up' />
<input type='submit' name='dname' value='Remove Name' /></form>" .
"<form name='delete' action='delete.php' method='POST'>
<input type='hidden' name='id' value='$id'/>";
if(isset($_SESSION['user_id'])){
echo "<input type='submit' name='delete' value='Delete Event' /></form>" .
"</td>";
}else{
echo "</form>" .
"</td>";
}
echo "</tr>";
}
echo "</table>";
echo "<br />";
}
?>
用户可以输入名称进行注册并删除其名称.
Users can enter a name to sign up and delete their name.
管理员可以添加和删除事件.
The admins can add and delete events.
有什么建议吗?
推荐答案
$getdates = mysql_query("SELECT DISTINCT date FROM namestable ORDER BY date DESC");
$dates = mysql_num_rows($getdate);
if($dates > 0){
echo "<table width='100%' cellspacing='0' cellpadding='0'>";
while ($rowdates = mysql_fetch_assoc($getdates)) {
$date = $rowdates['date'];
$getevents = mysql_query("SELECT * FROM namestable WHERE date = '$date' ORDER BY time ASC");
$events = mysql_num_rows($getevents);
if($events > 0){
echo "<tr><td>$date</td></tr>";
while ($rowevents = mysql_fetch_assoc($getevents)) {
$event_time = $rowevents['time'];
// all other info you want to pull here
echo "<tr><td>ROW WITH EVENT INFO HERE</td></tr>";
} // end event loop
} // end if events > 0
echo "</table>";
} // end if dates > 0
} // end date loop
这篇关于在多个HTML表格中显示结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!