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
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
Share on other sites

I am doing this in same way as urs except aliases.

$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";

and I told earlier that This is working fine in MySQL.

Link to comment
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.