Jump to content

Recommended Posts

I have three tables I\'m trying to combine. Two tables have information regarding a subject, and the third table is what I call the \"Connection\" table. I have the following query....


SELECT 

 a.comment_id, 

 a.name, 

 a.email, 

 a.comment, 

 a.live, 

 b.article_name,

 b.article_id,

 c.article_id, 

 c.comment_id, 

 c.commentjuke_id 

FROM 

 comments as a, 

 articles as b, 

 connect_commentarticles as c 

WHERE 

 c.article_id=\'$id\' 

 AND 

 a.comment_id=c.comment_id 

 AND 

 a.live=\'1\'";

Basically, Comments for articles are stored in one table. Articles content is stored in the other, and the third table pulls the two tables together (only three columns, for the article id, the comments id, and it\'s own id). I just want to pull the tables together but keep getting an error.

 

NOTE: the variable \"$id\" is the article id, that will be submitted by the user.

 

Please let me know if you can help!

Link to comment
https://forums.phpfreaks.com/topic/812-3-tables-1-query/
Share on other sites

Would this be right?

 

SELECT 

 a.comment_id, 

 a.name, 

 a.email, 

 a.comment, 

 a.live, 

 b.article_name, 

 b.article_id, 

 c.article_id, 

 c.comment_id, 

 c.commentjuke_id 

FROM 

 comments as a, 

 articles as b, 

 connect_commentarticles as c 

WHERE 

 b.article_id=\'$id\' 

 AND 

 c.article_id=b.article_id

 AND 

 a.comment_id=c.comment_id 

 AND 

 a.live=\'1\'";

Link to comment
https://forums.phpfreaks.com/topic/812-3-tables-1-query/#findComment-2690
Share on other sites

I keep getting an error ...

 

Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in...

 

Does it matter the order of the WHERE clause? For example, does it matter if \"b.article_id=c.article_id\" or \"c.article_id=b.article_id\"?

 

 

SELECT 

 a.comment_id, 

 a.name, 

 a.email, 

 a.comment, 

 a.live, 

 b.article_name, 

 c.article_id, 

 c.comment_id, 

 c.commentjuke_id 

FROM 

 comments as a, 

 articles as b, 

 connect_commentarticles as c 

WHERE 

 b.article_id=\'$id\' 

 AND 

 c.article_id=b.article_id 

 AND 

 a.comment_id=c.comment_id 

 AND 

 a.live=\'1\'";

Link to comment
https://forums.phpfreaks.com/topic/812-3-tables-1-query/#findComment-2693
Share on other sites

After I set my query; here\'s what I have....

 

$result2 = mysql_query($query1,$db);

$num_results = mysql_num_rows($result2);

if($num_results!=0)

{

    do {



         // PRINT INFORMATION FROM DATABASE



         } while ($myrow2 = mysql_fetch_array($result2));

}

Link to comment
https://forums.phpfreaks.com/topic/812-3-tables-1-query/#findComment-2696
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.