Jump to content

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

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.