I am trying to pull some information out of two tables and format it in an html table. This is my code, it tells me the query fails.
First, here are my two tables:
CREATE TABLE topicsTable (
topicId INT NOT NULL AUTO_INCREMENT,
topicName VARCHAR(50),
topicParent INT NULL,
PRIMARY KEY (topicID),
);
CREATE TABLE entryTable(
entryId INT NOT NULL AUTO_INCREMENT,
topicId INT,
topicBody TEXT,
PRIMARY KEY (entryId),
FOREIGN KEY (topicId) REFERENCES topicsTable (topicId)
);
here is the script as I have it now:
<?
include 'db.php';
$topicId=$_REQUEST['topicId'];
dbConnect("jmcclure_MyNotes");
$query = "SELECT topicName,topicBody
FROM topicsTable inner join entryTable
on topicsTable.topicId = entryTable.topicId
WHERE topicParent = $topicId";
$result = mysql_query($query) or die ("Query 'A' Failed " . mysql_error());
?>
<html>
<head>
<title>MyNotes</title>
</head>
<body>
<table border = '2'>
<?
while($row = mysql_fetch_assoc($result)){
print "<tr>";
print "<td>";
print $row['topicName'];
print "</td></tr>";
print "<tr>";
print "<td>";
print $row['topicBody'];
print "</td></tr>";
}
print "</table>";
?>
</body>
</html>
topicName is in the entryTable and topicBody is in the entryTable. both tables contain topicId. I need to be able to pull the original topic first where topicId is $topicId and parentTopic = null, then underneath it list the child topics where parentTopic = $topicId.
Any ideas?