Results 1 to 4 of 4

Thread: Creating Forums!

  1. #1
    Join Date
    May 2007
    Posts
    32
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Creating Forums!

    Hey there, im creating some forums and the database tables are as follows.

    forums_cat
    forums_boards
    forums_topics
    forums_posts

    When someone posts a new topic i am wanting this to happen:

    In the forums_topics table i'm wanting the topic_ID, topic_subject and topic_poster to be stored.

    I can do this fine but then it comes the problem when im trying to add to the posts table.

    in the posts table im wanting to add post_id, TOPIC_ID.

    How can i make it add the topic ID because it needs to get the ID from the topic just added.

  2. #2
    Join Date
    Jan 2007
    Location
    Davenport, Iowa
    Posts
    2,385
    Thanks
    100
    Thanked 113 Times in 111 Posts

    Default

    I think I have an idea of what you are asking, but it would be very helpful if you could post the code that you are having trouble with so we can look at what you are trying to do.

  3. #3
    Join Date
    Aug 2007
    Location
    Ohio
    Posts
    79
    Thanks
    0
    Thanked 15 Times in 15 Posts

    Default

    If you're using MySQL you can use the function mysql_insert_id. This function returns the id of the last insert query executed on the last link opened by mysql_connect(). Note: Your topic_id column needs to be auto incrementing for this function to retrieve it's value.

    Here's an example:
    Code:
    $subject = 'Whatever';
    $poster = 'Whoever';
    // add the topic
    mysql_query("INSERT INTO forums_topics (topic_subject, topic_poster) VALUES('".$subject."','".$poster."')");
    
    $topicid = mysql_insert_id();
    
    mysql_query("INSERT INTO forums_posts (topic_id) VALUES('".$topicid."')");
    
    // if you wanted the value of the auto increment column post_id, you could use mysql_insert_id() again.

  4. #4
    Join Date
    May 2007
    Posts
    32
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Thanks thats great!

Bookmarks

Posting Permissions

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