Results 1 to 2 of 2
  1. #1
    Join Date
    Nov 2005
    Posts
    5

    Unanswered: 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?

  2. #2
    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 .

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •