Jump to content

[SOLVED] mySQL query in multiple tables


Fabbuccino

Recommended Posts

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

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

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.