2013-03-26 169 views
0

我已經進入這裏一段時間了,但這是我第一次發佈。所以在這裏:MySQL查詢結果空白

我正在爲我的網站創建一個數據庫。到目前爲止,一切都很好,工作正常。但是當創建.php來顯示評論時,就好像回聲不存在一樣。

該代碼工作得很好,因爲我沒有得到任何可能的結果的任何錯誤。但在其中應該有結果,什麼也不顯示...

這裏是我的代碼:

<?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(); ?> 

就像我說的,代碼工作,我沒有得到任何錯誤。當沒有結果時,它會顯示「沒有評論...」的消息。都好。 問題是,什麼時候沒有結果顯示。請幫助??

+0

那裏有'echo'嗎? – 2013-03-26 02:45:20

回答

0

您的代碼格式是糟糕的。這裏。

<?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(); ?>