Sorun düzgün mySQL tabloları JOIN nasıl anlayış

0 Cevap php

Ok here is my problem. I'm adding a table to a existing database to store project notes.

"worklog" is the table with the projects "worklognotes" is the table with the project notes

The notes will be displayed like a discussion thread. worklognotes columns are set up like this id, worklog_id, timestamp, notes.

"id" is the table Unique id. "worklog_id" is the id of the project the note is pretaining to that is stored in another table. "timestamp" is well a Timestamp "notes" are the actual ongoing notes about the project. There could be many notes to a single project.

Looking at the database query below. I have joined the two queries "It's my first join so I'm not sure I've done it right." It is reading the information in both tables and displaying it. But the below code is displaying every entry in "worklog" that has a record in the "worklognotes" table. I need it to display one entry from "worklog" and many notes from "worklognotes"

Eğer yardım ya da bir yön önerebilirsiniz?

$connection = mysql_connect ("localhost", "user", "pass") or die ("I cannot connect to the database.");
$db = mysql_select_db ("database", $connection) or die (mysql_error());

$query = "SELECT * FROM worklog ";  
$query .= "JOIN worklognotes ON worklog_id = worklognotes.worklog_id ";  
$query .= "WHERE worklognotes.worklog_id=worklog.id ORDER BY worklognotes.id DESC";

0 Cevap