将变量SQL数据输出到表中。 6条记录,表示数据输出到6个单独的表,向下滚动页面。我想在并排表中放置两个记录集,然后用另一组双记录等开始一个新的表行,直到数据WHILE循环耗尽为止。问题是我不知道如何在WHILE循环中访问“下一条记录”数据集。将数据转储到数组更聪明,然后只是从数组计数器实现一个Next Record(N + 1直到记录计数器=“6”(在这种情况下))?请指教。 下面的代码 - 在一列表中可以正常工作。不确定是否有办法在2个并排表中输出数据,每个表三行。
$result = mysql_query("SELECT DISTINCT username FROM payroll");
print "<font size='+1'>Payments made for year <b>" . $payyear . "</b></font><br><br>";
while($row = mysql_fetch_array($result))
{
$username2=$row['username'];
$result2 = mysql_query("SELECT fullname, grossytd, taxytd, fedtaxytd, reghoursytd, othoursytd, ficassnytd, ficamedytd, statetaxytd, countytaxytd, netytd FROM payroll WHERE username = '$username2' ORDER BY (counter) DESC LIMIT 1");
while($row2 = mysql_fetch_array($result2))
{
$fullname1 = $row2['fullname'];
$grossytd1 = number_format($row2['grossytd'], 2);
$taxytd1 = number_format($row2['taxytd'], 2);
$fedtaxytd1 = number_format($row2['fedtaxytd'], 2);
$reghoursytd1 = number_format($row2['reghoursytd'], 2);
$othoursytd1 = number_format($row2['othoursytd'], 2);
$ficassnytd1 = number_format($row2['ficassnytd'], 2);
$ficamedytd1 = number_format($row2['ficamedytd'], 2);
$statetaxytd1 = number_format($row2['statetaxytd'], 2);
$countytaxytd1 = number_format($row2['countytaxytd'], 2);
$netytd1 = number_format($row2['netytd'], 2);
print "
<table border='1' cellpadding='1' cellspacing='1'>
<tr><td align='right'>Employee</td><td align='left' width='140'>" . $fullname1 . "</td> </tr>
<tr><td align='right'>Gross Pay</td><td align='left' width='100'>$" . $grossytd1 . "</td></tr>
<tr><td align='right'>Taxes Paid</td><td align='left' width='100'>$" . $taxytd1 . "</td></tr>
<tr><td align='right'>Federal Tax</td><td align='left' width='100'>$" . $fedtaxytd1 . "</td></tr>
<tr><td align='right'>Regular Hours</td><td align='left' width='140'>" . $reghoursytd1 . "</td></tr>
<tr><td align='right'>Overtime Hours</td><td align='left' width='140'>" . $othoursytd1 . "</td></tr>
<tr><td align='right'>Social Security</td><td align='left' width='100'>$" . $ficassnytd1 . "</td></tr>
<tr><td align='right'>Medicare</td><td align='left' width='100'>$" . $ficamedytd1 . "</td></tr>
<tr><td align='right'>State Taxes</td><td align='left' width='100'>$" . $statetaxytd1 . "</td></tr>
<tr><td align='right'>County Taxes</td><td align='left' width='140'>$" . $countytaxytd1 . "</td></tr>
<tr><td align='right'>Net Pay</td><td align='left' width='100'>$" . $netytd1 . "</td></tr>
";
}
print "</table>";
print "<br>";
}
答案 0 :(得分:0)
我认为做你想做的最简单的方法就是让表浮动。添加一些CSS规则,如下所示:
table {
width: 50%;
float: left;
}
如果由于表的宽度或长度而无效,那么另一个选项是在循环的每次迭代中都有一个从true翻转为false的标志。然后,如果该标志为true,则将该行的数据存储在变量中,如果该标志为false,则存储打印出先前保存的数据以及当前行的数据。如果您需要我详细说明第二种方法,请告诉我。