If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > MySQL > Searching Two Tables

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 11-13-05, 15:23
poisedforflight poisedforflight is offline
Registered User
 
Join Date: Nov 2005
Posts: 5
Searching Two Tables

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?
Reply With Quote
  #2 (permalink)  
Old 11-13-05, 23:30
jfulton jfulton is offline
Registered User
 
Join Date: Apr 2005
Location: Baltimore, MD
Posts: 297
As far as your first question goes...what is the error being produced? Throw in some validation code to make sure that $_REQUEST['topicId'] is returning the correct value.

As far as your second question goes...I didn't really understand it .
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On