我想根据一天显示不同的活动
表结构和我尝试过的查询如图所示
现在,时间表显示如下。我想在一行中将活动和日期分组在一起
Timesheet.php
<?php
include "connect.php";
$con=mysqli_connect("$host", "$username", "$password","$db_name")or die("Your Connection is in error");
$sql="SELECT timeid,userid,proid,actid,day(date) as DAY,monthname(date),time FROM timesheet where userid = '$id' ";
$results=mysqli_query($con,$sql);
$count=mysqli_num_rows($results);
if($count == 0)
{
echo "<script>";
echo " alert('No Details Found.');
window.location.href='indexmain.php';
</script>";
}
else
{
$resource=mysqli_query($con,$sql);
echo" <table border= \"1\" class = \"table table-bordered\">
<thead>
<tr>
<th width=\"2%\"><b>Id</b></th> <th width=\"4%\"><b>Project</b></th> <th width=\"4%\"><b>Activity</b></th>
<th width=\"2%\"><b>1</b></th> <th width=\"2%\"><b>2</b></th> <th width=\"2%\"><b>3</b></th>
<th width=\"2%\"><b>4</b></th> <th width=\"2%\"><b>5</b></th> <th width=\"2%\"><b>6</b></th>
<th width=\"2%\"><b>7</b></th> <th width=\"2%\"><b>8</b></th> <th width=\"2%\"><b>9</b></th>
<th width=\"2%\"><b>10</b></th> <th width=\"2%\"><b>11</b></th> <th width=\"2%\"><b>12</b></th>
<th width=\"2%\"><b>13</b></th> <th width=\"2%\"><b>14</b></th> <th width=\"2%\"><b>15</b></th>
<th width=\"2%\"><b>16</b></th> <th width=\"2%\"><b>17</b></th> <th width=\"2%\"><b>18</b></th>
<th width=\"2%\"><b>19</b></th> <th width=\"2%\"><b>20</b></th> <th width=\"2%\"><b>21</b></th>
<th width=\"2%\"><b>22</b></th> <th width=\"2%\"><b>23</b></th> <th width=\"2%\"><b>24</b></th>
<th width=\"2%\"><b>25</b></th> <th width=\"2%\"><b>26</b></th> <th width=\"2%\"><b>27</b></th>
<th width=\"2%\"><b>28</b></th> <th width=\"2%\"><b>29</b></th> <th width=\"2%\"><b>30</b></th>
<th width=\"2%\"><b>31</b> </tr>
</thead><tbody>";
while($result=mysqli_fetch_array($resource))
{
if ($result["DAY"] == "1") { $one = $result[6]; } else { $one = x; }
if ($result["DAY"] == "2") { $two = $result[6]; } else { $two = x; }
if ($result["DAY"] == "3") { $three = $result[6]; } else { $three = x; }
if ($result["DAY"] == "4") { $four = $result[6]; } else { $four = x; }
if ($result["DAY"] == "5") { $five = $result[6]; } else { $five = x; }
if ($result["DAY"] == "6") { $six = $result[6]; } else { $six = x; }
if ($result["DAY"] == "7") { $seven = $result[6]; } else { $seven = x; }
if ($result["DAY"] == "8") { $eight = $result[6]; } else { $eight = x; }
if ($result["DAY"] == "9") { $nine = $result[6]; } else { $nine = x; }
if ($result["DAY"] == "1x") { $ten = $result[6]; } else { $ten = x; }
if ($result["DAY"] == "11") { $eleven = $result[6]; } else { $eleven = x; }
if ($result["DAY"] == "12") { $twelve = $result[6]; } else { $twelve = x; }
if ($result["DAY"] == "13") { $thirteen = $result[6]; } else { $thirteen = x; }
if ($result["DAY"] == "14") { $fourteen = $result[6]; } else { $fourteen = x; }
if ($result["DAY"] == "15") { $fifteen = $result[6]; } else { $fifteen = x; }
if ($result["DAY"] == "16") { $sixteen = $result[6]; } else { $sixteen = x; }
if ($result["DAY"] == "17") { $seventeen = $result[6]; } else { $seventeen = x; }
if ($result["DAY"] == "18") { $eighteen = $result[6]; } else { $eighteen = x; }
if ($result["DAY"] == "19") { $ninenteen = $result[6]; } else { $ninenteen = x; }
if ($result["DAY"] == "2x") { $twenty = $result[6]; } else { $twenty = x; }
if ($result["DAY"] == "21") { $twoone = $result[6]; } else { $twoone = x; }
if ($result["DAY"] == "22") { $twotwo = $result[6]; } else { $twotwo = x; }
if ($result["DAY"] == "23") { $twothree = $result[6]; } else { $twothree = x; }
if ($result["DAY"] == "24") { $twofour = $result[6]; } else { $twofour = x; }
if ($result["DAY"] == "25") { $twofive = $result[6]; } else { $twofive = x; }
if ($result["DAY"] == "26") { $towsix = $result[6]; } else { $towsix = x; }
if ($result["DAY"] == "27") { $twoseven = $result[6]; } else { $twoseven = x; }
if ($result["DAY"] == "28") { $twoeight = $result[6]; } else { $twoeight = x; }
if ($result["DAY"] == "29") { $twonine = $result[6]; } else { $twonine = x; }
if ($result["DAY"] == "3x") { $thirty = $result[6]; } else { $thirty = x; }
if ($result["DAY"] == "31") { $threeone = $result[6]; } else { $threeone = x; }
echo "
<tr>
<td width=\"2%\"> <a href='timesheetdisplay2.php?timeid=".base64_encode($result[0])."'>".$result[0]."</td>
<td width=\"4%\">".$result[2]."</td>
<td width=\"4%\">".$result[3]."</td>
<td width=\"2%\">".$one."</td> <td width=\"2%\">".$two."</td>
<td width=\"2%\">".$three."</td> <td width=\"2%\">".$four."</td>
<td width=\"2%\">".$five."</td> <td width=\"2%\">".$six."</td>
<td width=\"2%\">".$seven."</td> <td width=\"2%\">".$eight."</td>
<td width=\"2%\">".$nine."</td> <td width=\"2%\">".$ten."</td>
<td width=\"2%\">".$eleven."</td> <td width=\"2%\">".$twelve."</td>
<td width=\"2%\">".$thirteen."</td> <td width=\"2%\">".$fourteen."</td>
<td width=\"2%\">".$fifteen."</td> <td width=\"2%\">".$sixteen."</td>
<td width=\"2%\">".$seventeen."</td> <td width=\"2%\">".$eighteen."</td>
<td width=\"2%\">".$ninenteen."</td> <td width=\"2%\">".$twenty."</td>
<td width=\"2%\">".$twoone."</td> <td width=\"2%\">".$twotwo."</td>
<td width=\"2%\">".$twothree."</td> <td width=\"2%\">".$twofour."</td>
<td width=\"2%\">".$twofive."</td> <td width=\"2%\">".$towsix."</td>
<td width=\"2%\">".$twoseven."</td> <td width=\"2%\">".$twoeight."</td>
<td width=\"2%\">".$twonine."</td> <td width=\"2%\">".$thirty."</td>
<td width=\"2%\">".$threeone."</td>
</tr>";
} echo "</tbody></table>";
}
?>
我尝试过的代码附在这篇文章中。我需要在同一行中显示不同的活动和日期,如下所示
我希望查询产生这样的结果。