我已经来这里有一段时间了,但这是我第一次发帖。它是这样的:
我正在为我的网站创建一个数据库。到目前为止,一切都很顺利。但是当创建.php来显示注释时,就好像echo根本不存在一样。
代码工作得很好,因为我没有在任何可能的结果上得到任何错误。但在那些应该有结果的地方,什么也没有出现……
这是我的代码:
<?php $pickstory=$_POST['pickstory'];
$result = mysql_query("SELECT name, comment
FROM originalwork
WHERE story = '$pickstory'", $conexion);
if($fila= mysql_fetch_row($result)!=0){ ?>
<?php echo "<h6>Comments on $pickstory</h6>"; ?>
<table width="900">
<tr>
<td width="159" align="left" valign="top"></td>
<td width="729"></td>
</tr>
<?php while ($fila= mysql_fetch_row($result)) { ?>
<tr>
<td><?php echo "<h2>Name: $fila[0]</h2>"; ?></td>
<td><?php echo "<p>$fila[1]</p>"; }?></td>
</tr>
<?php } else { echo "<h5>No comments on $pickstory so far. Be the first!</h5>"; } ?>
</table>
<?php mysql_free_result($result); mysql_close(); ?>
就像我说的,代码工作,我没有得到任何错误。当没有结果时,它会显示"no comments…"。所有的好。问题是,当有结果的时候,什么都显示不出来。帮助吗? ?
你的代码格式是可怕的。这里。
<?php
$pickstory = $_POST['pickstory'];
$result = mysql_query("SELECT name, comment
FROM originalwork
WHERE story = '$pickstory'", $conexion);
?>
<?php if(($fila = mysql_fetch_row($result)) !== false): ?>
<h6>Comments on <?=$pickstory?></h6>
<table width="900">
<tr>
<td width="159" align="left" valign="top"></td>
<td width="729"></td>
</tr>
<?php while (($row = mysql_fetch_row($result)) !== false): ?>
<tr>
<td><h2>Name: <?=$row[0]?></h2></td>
<td><p><?=$row[1]?></p></td>
</tr>
<?php endwhile; ?>
<?php else: ?>
<h5>No comments on <?=$pickstory?> so far. Be the first!</h5>
<?php endif; ?>
</table>
<?php mysql_free_result($result); mysql_close(); ?>