我正在建立一个报告,该报告将从数据库中提取信息。当其他用户完成与客户的工作时,我有一个新表出现,我可以正常工作。我以前使用过此代码,但是由于某些原因,在与其他客户端一起使用后,users表中没有追加新行。就像如果我为一个Google项目工作了一个小时,就会出现,就像我为一个Yahoo项目工作了一个小时,那么只会出现Yahoo数据。我希望这两个都出现在表格中。任何帮助或建议都将不胜感激,谢谢!
// Connecting, selecting database
$link = mysql_connect('localhost', $username, $password)
or die('Could not connect: ' . mysql_error());
//echo 'Connected successfully';
mysql_select_db($database) or die('Could not select database');
//loop thru users
$sql0 = "SELECT distinct idManager,(select email from users where id = u.idManager) as email from users u where id in(select userid from reports where DATE(timestamp) = CURDATE())";
$zresults = mysql_query($sql0) or die('Query failed: ' . mysql_error());
$z=0;
$msg = "";
$zum=mysql_numrows($zresults);
while ($z < $zum) {
$Mid=mysql_result($zresults,$z,"idManager");
$Mmail=mysql_result($zresults,$z,"email");
//echo $uid;
$sql = "SELECT id, timestamp, (sum((timeout+0) - (timein+0))) as TotalDurationDays,(select username from users where id = r.userid) as user, (select client from clients where id = r.clientid) as client, timein, timeout, openissues, otherissues from reports r where DATE(timestamp) = CURDATE() and userid in(select id from users where idManager = $Mid) order by (select username from users where id = r.userid) asc, (select client from clients where id = r.clientid) asc, timestamp desc";
$results = mysql_query($sql) or die('Query failed: ' . mysql_error());
$aum=mysql_numrows($results);
//mysql_close();
$a=0;
$c = true;
//$msg = "<table><tr><td>Placeholder</td></tr></table>";
$msg = $msg ."<h3>Individual User Updates</h3><table border='1' cellspacing='3' style='margin-left:1.5em;'>
<tr>
<th>Date</th>
<th>User</th>
<th>Client</th>
</tr>";
while ($a < $aum) {
$Id=mysql_result($results,$a,"id");
$TotalTime=mysql_result($results,$a,"TotalDurationDays");
$Timein=mysql_result($results,$a,"timein");
$Timeout=mysql_result($results,$a,"timeout");
$Date=date_format(date_create(mysql_result($results,$a,"timestamp")),'m/d/y');
$User=mysql_result($results,$a,"user");
$Client=mysql_result($results,$a,"client");
$Open=mysql_result($results,$a,"openissues");
$Other=mysql_result($results,$a,"otherissues");
$msg = $msg . "<tr".(($c = !$c)?" class='odd'":"class='even'")."><td nowrap>" . $Date . "</td><td nowrap>" . $User . "</td><td style='text-align:center;'>" . $Client . "</td></tr><tr style='background-color: #dddddd;'>
<td></td><td style='text-align:right;font-weight:bold;'>Total Hours:</td><td class='total-hours' id='total-hours' style='text-align:center;'>" . $TotalTime ." mins. </td></tr>";
$a++;
}
$msg = $msg. "</table><br><hr>";
$z++;
}
//end user loop
mysql_close();
echo $msg;
?>