开发者

getting mysql field as blank although its there !

开发者 https://www.devze.com 2023-02-01 21:59 出处:网络
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

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- '开发者_如何学JAVAsid' 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?


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


$sid=$promoted_article['sid'];

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


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消