我在下面的脚本中遇到了一些问题,基本上我想要实现的是获取不同的产品和价格并生成一个工作正常的表。但是,有些产品确实需要额外收费,在这种情况下,产品将使用三排(价格,额外费用和总和)。我试图让IF语句按如下方式工作:如果额外费用= 0那么它应该只在表中产生一行,如果大于0,它应该产生3行版本。
有人知道我做错了什么吗?提前谢谢!
<?php
$page=basename($_SERVER['PHP_SELF']); /* Returns PHP File Name */
$page_name=str_replace(".php","",$page);
mysql_connect(localhost,$dbuser,$dbpass);
@mysql_select_db($database) or die( "Unable to select database");
$query= ("SELECT * FROM table e
JOIN validdate1 r ON e.datevalid1=r.id
JOIN validdate2 d ON e.datevalid2=d.id
WHERE productpage='$page_name'
ORDER BY productname,price2");
$result=mysql_query($query);
$num=mysql_numrows($result);
mysql_close();?>
<table>
<thead>
<tr>
<th class="headerdesc">Description</th>
<th class="headerprice1 rates1">2015</th>
<th class="headerprice2 rates2">2016</th>
</tr>
</thead>
<?php $i=0;while ($i < $num)
{
$productname = mysql_result($result,$i,"productname");
$price1=mysql_result($result,$i,"price1");
$price2=mysql_result($result,$i,"price2");
$extracharge1=mysql_result($result,$i,"extracharge1");
$extracharge2=mysql_result($result,$i,"extracharge2");
$daterange1=mysql_result($result,$i,"daterange1");
$daterange2=mysql_result($result,$i,"daterange2");
if ($extracharge1 > "0") {
echo " <tr>
<td class="desc"><?php echo $productname; ?></td>
<td class="price1 rates1">$<? echo $price1; ?></td>
<td class="price2 rates2">$<? echo $price2; ?></td>
</tr>
<tr>
<td class="extra">Extra Charge**</td>
<td class="price1 rates1">$<? echo $extracharge1; ?></td>
<td class="price2 rates2">$<? echo $extracharge2; ?></td>
</tr>
<tr class="lastrow">
<td class="totalprice"><strong>Total price</strong></td>
<td class="total rates1"><strong>$<? echo $price1+$extracharge1; ?></strong></td>
<td class="total rates2"><strong>$<? echo $price2+$extracharge2; ?></strong></td>
</tr>";
} else {
echo " <tr class="lastrow">
<td class="extra"><?php echo $productname; ?></td>
<td class="price1 rates1">$<? echo $price1; ?></td>
<td class="price2 rates2">$<? echo $price2; ?></td>
</tr>";
}
?>
<?php $i++;}?>
</table>