Jump to content

Complicated Query


chibineku
 Share

Recommended Posts

I am a little baffled by this query:

$verify_sql = "SELECT ft.topic_id, ft.topic_title FROM forum_posts AS fp LEFT JOIN forum_topics AS ft ON fp.topic_id = ft.topic_id WHERE fp.post_id = '".$_GET["post_id"]."'";

Obviously I have two tables, one called forum_topics and one call forum_posts, and there are some PHP elements, but the workings of the query are not explained in the book from which this example comes. I understand how everything else works, though, but the author does not explain this query, merely calling it complicated looking...

Link to comment
Share on other sites

It's doing a left join, so it's going to select the records from the forum_posts table and, if there are matching records from the forum_topics table for that post, it will also select those matching records. It's not returning anything from the forum_posts table, but it looks like it's trying to look up a certain post ID, so it's getting information about the topic for that post. Look up SQL joins if you want more information about how they work.

Link to comment
Share on other sites

I understand basic joins, though I can never remember them without looking them up, but it's the fp / ft business. I guess one stands for forum_topics and the other for forum_posts, but I wasn't aware it was necesary to create new names like that.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...