开发者

Not able to display one item from query result - PHP/MySQL

So, weird issue.

Here's the code:

//connect and execute query
mysql_connect('127.0.0.1','user','password');
@mysql_select_db('db_name') or die( "Unable to select database");

$query="SELECT node_revisions.nid, node_revisions.title, content_type_training_event.field_course_url_value
    FROM node_revisions, content_type_training_event
    WHERE body LIKE '%{$term}%' AND node_revisions.nid IN (SELECT nid FROM content_type_training_event) AND content_type_training_event.nid = node_revisions.nid";

$result=mysql_query($query);

$num = mysql_numrows($result);  

if ($num > 0)
{
while ($col = mysql_fetch_assoc($result)) 
{       

$nid=trim($col["nid"]);
$title=trim($col["title"]);
$url=trim($col["field_course_url_value"]);

}
}

//OK weird part...

echo($nid . $title . $url);

So,开发者_Go百科 what happens is $title and $url are printed to screen, but $nid is not. When I run the same query inside MySQL Admin, I get the nid.

Any ideas? This is driving me nuts.


Maybe because there is an NID in multiple tables. Alias the NID in your query as follows:

$query="SELECT node_revisions.nid as nid, node_revisions.title, content_type_training_event.field_course_url_value
    FROM node_revisions, content_type_training_event
    WHERE body LIKE '%{$term}%' AND node_revisions.nid IN (SELECT nid FROM content_type_training_event) AND content_type_training_event.nid = node_revisions.nid"

I certainly could be wrong; feel free to downvote :)


Try

SELECT node_revisions.nid as currentNid, node.....

And then

$nid=trim($col["currentNid"]);
$title=trim($col["title"]);
$url=trim($col["field_course_url_value"]);
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜