How do I write this SQL statement to get the ad and posting? (PHP/MySQL)
- by ggfan
I am a little confused on the logic of how to write this SQL statement. When a user clicks on a tag, say HTML, it would display all the posts with HTML as its tag. (a post can have multiple tags)
I have three tables:
Posting--posting_id, title, detail,
etc
tags--tagID, tagname
postingtag--posting_id, tagID
I want to display all the title of the post and the date added.
global $dbc;
$tagID=$_GET['tagID']; //the GET is set by URL
//part I need help with. I need another WHERE statment to get to the posting table
$query = "SELECT p.title,p.date_added, t.tagname FROM posting as p,
postingtag as pt, tags as t WHERE t.tagID=$tagID";
$data = mysqli_query($dbc, $query);
echo '<table>';
echo '<tr><td><b>Title</b></td><td><b>Date Posted</b></td></tr>';
while ($row = mysqli_fetch_array($data)) {
echo '<tr><td>'.$row['title'].'</td>';
echo '<td>'.$row['date_added'].'</td></tr>';
}
echo '</table>';
}