将数据追加到表中的新行

htrmnn0y  于 2021-06-15  发布在  Mysql
关注(0)|答案(0)|浏览(244)

我正在建立一个从数据库中提取信息的报告。我有一个新的表出现时,不同的用户完成他们的工作与客户端,我有这个工作正常。我以前使用过这段代码,但由于某种原因,在用户使用不同的客户机之后,不会在users表中追加新行。比如,如果我为谷歌工作一个小时,就会出现,如果我为雅虎工作一个小时,只会出现雅虎数据。我希望这两个都出现在一张table上。非常感谢您的帮助和建议,谢谢!

// 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;
?>

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题