用while循环填充表

时间:2012-12-30 12:17:23

标签: php

我正在尝试填充从MySQL数据库中提取数据的表,数据库中有3个条目,但由于某种原因回显数据不起作用,尽管我可以看到它经历了3次循环(该表创建3个复选框,每个条目1个)

代码

<?php 
    $qry2="SELECT * FROM buytraff WHERE username='$username'";
    $result2=mysql_query($qry2) or die(mysql_error()); 
    while ($rows = mysql_fetch_assoc($result2)):?>

<tr class="first">
<td class="tc">&nbsp;</td>
<td class="tc"><center><font face="Arial, Helvetica, sans-serif"></font><font face="Arial, Helvetica, sans-serif"><? echo $rows['id']; ?></font>
</center></td>
<td class="tc"><center><font face="Arial, Helvetica, sans-serif"><? echo $rows['url']; ?></font></center></td>

<td><center><font face="Arial, Helvetica, sans-serif"><? echo $rows['nichecountry']; ?></font></center></td>
<td class="tc"><center><font face="Arial, Helvetica, sans-serif"><?php if($rows['type']=='1.99'){
echo "something";
}

elseif($rows['type']=='2.99'){
echo "something";
}

elseif($rows['type']=='3.00'){
echo "something";
}

elseif($rows['type']=='4.00'){
echo "something";
}

?></font></center></td>
<td class="tc"><center><font face="Arial, Helvetica, sans-serif"><? echo $rows['price']; ?> $</font></center></td>
<td class="tc"><center><font face="Arial, Helvetica, sans-serif"><? echo $rows['amount']; ?></font></center></td>
<td class="tc"><center><font face="Arial, Helvetica, sans-serif"><? echo $rows['delivered']; ?></font></center></td>
<td class="tc"><center><font face="Arial, Helvetica, sans-serif"><? echo $rows['status']; ?></font></center></td>
<td class="tc"><center><input name="checkbox[]" type="checkbox" class="checkbox" id="checkbox[]" value="<? echo $rows['id']; ?>"></center></td> 
</tr>
<?php endwhile; ?>

1 个答案:

答案 0 :(得分:1)

使用PHP短标签

在XAMPP中,您需要在PHP.ini中启用此选项:

short_open_tag = On