Jump to content

A problem in a query


abhi80

Recommended Posts

Hi All,

 

I am a new comer in php. earlier I was involved in ASP.

Currently I am facing a problem.

 

I have created 2 tables as:

 

1.

CREATE TABLE dtopics (

  topicId int(11) NOT NULL auto_increment,

  topicName text,

  dateAdded date default NULL,

  PRIMARY KEY  (topicId)

) TYPE=MyISAM;

 

 

2.

CREATE TABLE tcomments (

  commentId int(10) unsigned NOT NULL auto_increment,

  comment text,

  topicId int(10) NOT NULL default '0',

  postedBy varchar(100) default NULL,

  postdate timestamp(14) NOT NULL,

  isActive enum('True','False') default 'False',

  PRIMARY KEY  (commentId),

  KEY postdate (postdate)

) TYPE=MyISAM;

 

now I am running a query against these tables:

 

$qt="Select T.*, D.topicName from tcomments T inner join dtopics D on T.topicId=D.topicId where T.topicId=$tid AND isActive='False' Order By postDate DESC";

 

while($result_set=mysql_fetch_array($result1))

{

    //show data

}

 

but this query is returning nothing.

 

Though I tried to run same query in MYSQL and it returned expected results.

 

but in php page it is not returning any thing.

 

Could somebody please tell me where I am making a mistake?

 

 

Link to comment
https://forums.phpfreaks.com/topic/40474-a-problem-in-a-query/
Share on other sites

I am getting $tid from a query string as:

 

$tid=$_REQUEST['tid'];

 

and I am running the same query as posted by you.

 

$qt="Select T.*, D.topicName from tcomments T inner join dtopics D on T.topicId=D.topicId where T.topicId='$tid' AND isActive='False' Order By postDate DESC";

Link to comment
https://forums.phpfreaks.com/topic/40474-a-problem-in-a-query/#findComment-195823
Share on other sites

You didn't define T or D... Could that be the problem?

 

I think something like this?:

Select tcomments.*, dtopics.topicName from tcomments as T inner join dtopics as D on T.topicId=D.topicId where T.topicId=$tid AND isActive='False' Order By postDate DESC

Link to comment
https://forums.phpfreaks.com/topic/40474-a-problem-in-a-query/#findComment-195829
Share on other sites

Sorry I skipped that part

 

Did you try this?:

 

$qt="Select T.*, D.topicName from tcomments T inner join dtopics D on T.topicId=D.topicId where T.topicId=$tid AND isActive='False' Order By postDate DESC";
$result1 = mysql_query($qt) or die(mysql_error());
while($result_set=mysql_fetch_array($result1))
{
    echo $result_set['topicName'];
}

Link to comment
https://forums.phpfreaks.com/topic/40474-a-problem-in-a-query/#findComment-195837
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.