2013-12-21 67 views
-1

我不斷收到錯誤消息 「資源ID#26」 在PHP中:獲取資源ID#26 PHP錯誤

$R = mysql_query("SELECT * FROM Replies WHERE tid='$gS->ID' ORDER BY ID DESC LIMIT  1"); 
?> 

    <tr style="<? echo "$scss"; ?>"> 
    <td width="560" class="thread" colspan="4" height="70" style="" border-left: 1px solid gainsboro;text-align: center;"><center><a href="./Post.php?id="><? echo "$gS->Title";  ?></center></a> 
    <td width="100" align="center" class="thread" style="text-align: center;" valign="middle"><? echo "$R"; ?></td> 
    <td width="100" align="center" class="thread" valign="middle"></td> 
    <td width="200" class="thread" style="border-right: 1px solid gainsboro;">by <? echo "$LastReply"; ?> <br>January, 1st, 2000 - 2:00am</td> 
    </tr> 
</table> 
+0

['mysql_query'](http://php.net/mysql_query)不返回任何值。你仍然需要'_fetch_xy()'它們。 – mario

+0

你正在迴應你的記錄集。你可能會想'mysql_fetch_array()'或其他。 – andrewsi

回答

1

您需要獲取查詢結果這樣

$R = mysql_query("SELECT * FROM Replies WHERE tid='$gS->ID' ORDER BY ID DESC LIMIT  1"); 

因爲$R是隻有一個結果,你不需要使用while。使用mysql_fetch_assoc()

$row= mysql_fetch_assoc($R); 

打印使用

<?php echo $row['FieldName'];?> 

嘗試更新到庫MySQLi或PDO

Why shouldn't I use mysql_* functions in PHP?

+0

它只是給出了一個空白的結果。 – user3124505