尽管 mysql 字段在那里,但它却显示为空白!

发布于 2024-10-10 08:20:14 字数 459 浏览 0 评论 0原文

我在这个bug上花了很多时间,但找不到错误。我在 mysql 数据库中有一个名为“stories”的表,其中包含许多字段,包括“sid”、“title”和“content”。我正在尝试使用 PHP 访问这些字段:

$sql=mysql_query("SELECT sid,title,content FROM stories WHERE (promoted=1 and published=1) ORDER BY post_time DESC LIMIT 0,1");

$promoted_article=mysql_fetch_array($sql);

$sid=$promoted_article[sid];

echo $sid;

通过 phpmyadmin 我已经检查了所有内容 - 'sid' 是一个自动增量字段,因此每条记录都存在。然而“$sid”到处都是空的。我根本无法理解这个问题。任何人都知道为什么会发生这种情况?

I have spent a hell lot of time on this bug and I can't find the error. I have a table in a mysql database name 'stories' with many fields, including 'sid','title' and 'content'. I am trying to access these fields using PHP:

$sql=mysql_query("SELECT sid,title,content FROM stories WHERE (promoted=1 and published=1) ORDER BY post_time DESC LIMIT 0,1");

$promoted_article=mysql_fetch_array($sql);

$sid=$promoted_article[sid];

echo $sid;

Through phpmyadmin I've checked everything- 'sid' is an auto-increment field and so exists for every record. However '$sid' comes out to be null everywhere. I cannot understand the problem at all. Anyone has the slightest idea why this may be occuring?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

时光是把杀猪刀 2024-10-17 08:20:14

$sid=$promoted_article[sid];

PHP 认为 sid 是一个常量,你应该在它周围使用撇号,如下所示:
$sid=$promoted_article['sid'];

它可能与您的查询无关,除非这不起作用^

$sid=$promoted_article[sid];

PHP thinks sid is a constante, you should use apostrofs around it like this:
$sid=$promoted_article['sid'];

It probably has nothing to do with your query, unless this doesn't work ^

不疑不惑不回忆 2024-10-17 08:20:14
$sid=$promoted_article['sid'];

您缺少 $promoted_article 数组索引的 '

$sid=$promoted_article['sid'];

You are missing the ' for the index of the $promoted_article array

独自唱情﹋歌 2024-10-17 08:20:14

通过读取输出来测试您的结果,

print_r($promoted_article);

以查明查询或从结果集中检索数据是否有问题。

Test you result by reading output of

print_r($promoted_article);

To find out if it is problem with query or with retrieving data from result set.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文