A problem in query

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
abhi80
Forum Newbie
Posts: 3
Joined: Tue Feb 27, 2007 11:46 pm

A problem in query

Post by abhi80 »

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


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.
[syntax="sql"]
CREATE TABLE dtopics (
  topicId int(11) NOT NULL auto_increment,
  topicName text,
  dateAdded date default NULL,
  PRIMARY KEY  (topicId)
) TYPE=MyISAM;
2.

Code: Select all

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:[/syntax]

Code: Select all

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


feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

How does $result1 get set?
abhi80
Forum Newbie
Posts: 3
Joined: Tue Feb 27, 2007 11:46 pm

Post by abhi80 »

Sorry I forgot to paste that line of code:

That is:

Code: Select all

$result1 = mysql_query($qt) or die(mysql_error());
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Does echoing $qt provide any insight?
abhi80
Forum Newbie
Posts: 3
Joined: Tue Feb 27, 2007 11:46 pm

Post by abhi80 »

After echoing $qt:

Code: Select all

Select T.*, D.topicName from tcomments T inner join dtopics D on T.topicId=D.topicId where T.topicId=5 AND isActive='True' Order By postDate DESC
User avatar
daedalus__
DevNet Resident
Posts: 1925
Joined: Thu Feb 09, 2006 4:52 pm

Post by daedalus__ »

Post Reply