Setting up a DataBase with 'Tagging'

Discussion in 'Databases' started by RogerDodgr, Jan 21, 2011.

  1. #1
    I am trying to start a database with a tagging system that consists of two tables:
    1. Q&A: A table with: ID, Questions & Answers.
    2. Tags: A table with: ID & Tags.

    Both tables share a common ID. In phpMyAdmin, I set up the 'Q&A' table with the ID set to auto-increment, so that I can reference each record with a unique ID. The IDs in the 'Tags' table are not unique because each IDs can have multiple words (tags) associated with it.

    I wrote some records to the Q&A database without any problem. But now I am stuck on how to get the unique ID (as the unique ID is being automatically created) in the Q&A table, so that that ID can be used for some number of records in the tags table.
     
    RogerDodgr, Jan 21, 2011 IP
  2. AstarothSolutions

    AstarothSolutions Peon

    Messages:
    2,680
    Likes Received:
    77
    Best Answers:
    0
    Trophy Points:
    0
  3. RogerDodgr

    RogerDodgr Well-Known Member

    Messages:
    267
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    105
    #3
    Works. If anyone is curious...
    $con = mysql_connect("***","***","***");
    
    ...
    
    $sql="INSERT INTO lessons (question, answer, html, tags) VALUES ('$question', '$answer', '$html', '$tags')";
    		
    ...
    	
    echo "<h1>" . mysql_insert_id($con) . "</h1>";
    
    PHP:
    The last line prints the last auto-increment value from the table that was just inserted. (mysql_insert_id knows which column is auto-incremented.)
     
    Last edited: Jan 23, 2011
    RogerDodgr, Jan 23, 2011 IP
  4. iliveforyou

    iliveforyou Active Member

    Messages:
    207
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    53
    #4
    well done and thank you for sharing the solution
     
    iliveforyou, Jan 24, 2011 IP