【问题标题】:Getting Resource id #26 PHP Error [duplicate]获取资源 id #26 PHP 错误 [重复]
【发布时间】:2013-12-21 02:43:02
【问题描述】:

我在 PHP 中不断收到错误“Resource 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>

【问题讨论】:

  • mysql_query 不返回任何值。你仍然需要_fetch_xy()他们。
  • 您正在回显您的记录集。你可能想要mysql_fetch_array() 或类似的。

标签: php mysql


【解决方案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?

【讨论】:

  • 它只是给出一个空白的结果。
猜你喜欢
  • 2011-10-31
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-06-08
  • 1970-01-01
  • 2014-04-06
  • 2017-06-29
  • 2014-11-18
相关资源
最近更新 更多