我希望红色颜色作为表格最后一行的背景。
但它没有改变。
我试过了:
$i = 0;
$total = 0;
$stmttr = $user_home->runQuery("SELECT * FROM invoice WHERE BRN = :inv"); // Your query
$stmttr->bindParam(':inv',$irn);
$allRows = $stmttr->rowCount(); // Count Total rows available in result
$tri = 0; // initiate variable to check <tr> status
while($rowc)
{
extract($rowc);
$i++;
?>
<tr <?php if(++$tri==$allRows) { ?> style="background-color: red;"<?php } ?> >
<td style="border-top:none !important; border-bottom:none !important;">
请参阅完整代码:
<?php
$i = 0;
$total = 0;
$stmttr = $user_home->runQuery("SELECT * FROM invoice WHERE BRN = :inv"); // Your query
$stmttr->bindParam(':inv',$irn);
$allRows = $stmttr->rowCount(); // Count Total rows available in result
$tri = 0; // initiate variable to check <tr> status
while($rowc)
{
extract($rowc);
$i++;
?>
<tr <?php if(++$tri==$allRows) { ?> style="background-color: red;"<?php } ?> >
<td style="border-top:none !important; border-bottom:none !important;">
<?php echo $i; ?>
</td>
<td style="border-top:none !important; border-bottom:none !important;">
<?php
$itm = $IRN;
$stmti = $user_home->runQuery('SELECT * FROM item WHERE IRN = :iinv ');
$stmti->bindParam(':iinv',$itm);
$stmti->execute();
$rowci = $stmti->fetch(PDO::FETCH_ASSOC);
echo $rowci['Name'];
$srv = $SRN;
$stmts = $user_home->runQuery('SELECT * FROM service WHERE SRN = :sinv ');
$stmts->bindParam(':sinv',$srv);
$stmts->execute();
$rowcs = $stmts->fetch(PDO::FETCH_ASSOC);
?>
(<?php echo $rowcs['Name']; ?>)
</td>
<td style="border-top:none !important; border-bottom:none !important;">
<?php echo $Quantity; ?>
</td>
<td style="border-top:none !important; border-bottom:none !important;">
<?php echo $Amnt; ?>
</td>
</tr>
答案 0 :(得分:1)
错误发生在:$allRows = $stmttr->rowCount(); // Count Total rows available in result
不计算MySQL中可用的行
更新的代码:
$i = 0;
$total = 0;
$stmttr = $user_home->runQuery("SELECT COUNT(*) As rows FROM invoice WHERE BRN = :inv"); // Your query
$stmttr->bindParam(':inv',$irn);
$stmttr->execute();
$cresult = $stmttr->fetch(PDO::FETCH_ASSOC);
$tf= ($cresult['rows']);
while($rowc)
{
extract($rowc);
$i++;
?>
<tr <?php if($i == $tf) { ?> style="background-color: red;"<?php } ?> >
<td style="border-top:none !important; border-bottom:none !important;">
希望它对你有所帮助。祝你好运!!
答案 1 :(得分:0)
<table>
和<tr>
之前添加</table>
最后</tr>
?CSS应该在css文件中,更好的练习!
我没有你的数据库,但是这个代码正常,如果它是你想要的。
<?php
$tri = 0;
$nbrows=10;
?>
<table>
<?php
while ($tri<$nbrows) { ?>
<tr <?php if(++$tri==$nbrows) { echo "style=\"background-color: red;\"";} ?> >
<td style="border-top:none !important; border-bottom:none !important;">Your content </td>
<td style="border-top:none !important; border-bottom:none !important;">Content 2 </td>
</tr>
<?php
}
?>
</table>