获取资源ID#26 PHP错误

时间:2013-12-21 02:43:03

标签: php mysql

我在PHP中不断收到错误“资源ID#26”:

$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>

1 个答案:

答案 0 :(得分: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?