尽管 mysql 字段在那里,但它却显示为空白!
我在这个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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
$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 ^
您缺少
$promoted_article
数组索引的'
You are missing the
'
for the index of the$promoted_article
array通过读取输出来测试您的结果,
以查明查询或从结果集中检索数据是否有问题。
Test you result by reading output of
To find out if it is problem with query or with retrieving data from result set.