有人可以在下面的代码中指出我做错了什么吗?我收到了“意外的T_WHILE”错误。
echo '
<table border="1">
<tr>
<td>Events</td>
<td>Category</td>
</tr>
<tr>
<td>', while ($row = mysql_fetch_assoc($queryresult)) { $title = $row['eventTitle']; echo $title; }, '</td>
<td>', while ($row = mysql_fetch_assoc($queryresult)) { $category = $row['eventTitle']; echo $category; }, '</td>
</tr>
</table> ';
答案 0 :(得分:1)
试试这个
首先,关闭PHP标记。
?>
<table border="1">
<tr>
<td>Events</td>
<td>Category</td>
</tr>
<tr>
<td>
<?php
while ($row = mysql_fetch_assoc($queryresult)) {
$title = $row['eventTitle'];
echo $title;
}
?>
</td>
<td>
<?php
while ($row = mysql_fetch_assoc($queryresult)) {
$category = $row['eventTitle'];
echo $category;
}
?>
</td>
</tr>
</table>
答案 1 :(得分:1)
PHP -
$array = array();
$i = 0;
while ($row = mysql_fetch_assoc($queryresult))
{
$array[$i]['title'] = $row['eventTitle'];
$array[$i]['category'] = $row['eventCategory'];
$i++;
}
HTML -
<table border="1">
<tr>
<td>Events</td>
<td>Category</td>
</tr>
<?php
foreach($array as $arr)
{
?>
<tr>
<td><?php echo $arr['event']; ?></td>
<td><?php echo $arr['category']; ?></td>
</tr>
<?php
}
?>