Fabbuccino Posted September 21, 2009 Share Posted September 21, 2009 This is my code $teid = $_GET['catid']; // list all articles found $result = @mysql_query("SELECT authorid, article, articletitle, dateadded, authorid FROM articles, authors WHERE articles.id=" . $teid . " AND authorid=authors.id"); I tried many things and it keeps giving me this error Error performing query: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'AND authorid=authors.id' at line 1 now just to give you a background on what's happening i have two tables...as u can see. articles and authors the tables look similar to this articles ====== id | article | authorid ====== authors ====== id | name | email basically..i want the query to grab the article id from the previous page [saved in the url], and then get the authorid in the same entry, and use the to set the authors id. if i ONLY put authorid=authors.id, it works, but then it just lists every article...yes it does it in order of authors, which is fine, but i only want the article of the id given..how do i do that? Link to comment https://forums.phpfreaks.com/topic/174980-solved-mysql-query-in-multiple-tables/ Share on other sites More sharing options...
kickstart Posted September 21, 2009 Share Posted September 21, 2009 Hi Is catid numeric? I would try something like this:- $teid = ((is_numeric($_GET['catid'])) ? $_GET['catid'] : 0); // list all articles found $result = @mysql_query("SELECT authorid, article, articletitle, dateadded, authorid FROM articles INNER JOIN authors ON articles.authorid=authors.id WHERE articles.id=" . $teid . " "); All the best Keith Link to comment https://forums.phpfreaks.com/topic/174980-solved-mysql-query-in-multiple-tables/#findComment-922206 Share on other sites More sharing options...
Fabbuccino Posted September 21, 2009 Author Share Posted September 21, 2009 dw. i got it. lol. my bad thanks for your time btw Link to comment https://forums.phpfreaks.com/topic/174980-solved-mysql-query-in-multiple-tables/#findComment-922207 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.