SitePoint Sponsor

User Tag List

Results 1 to 9 of 9

Hybrid View

  1. #1
    SitePoint Enthusiast Hakaslak's Avatar
    Join Date
    Nov 2006
    Location
    Nowhere.
    Posts
    28
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    php /mysql custom coded forum help needed

    I am trying to put together my own forum.

    I have a MySQL table called "posts". it has a field called "post_thread_id". Now, if I didn't want to create a separate threads table, how could I set it so that when a new thread is created, "post_thread_id" is set to auto_increment, but when it is a reply to an existing thread, it would use $_GET to grab the current thread_id? I don't think PHP can modify MySQL table attributes on the fly, and I don't know how to use PHP to generate a consistent stream of auto_increment numbers.

    Something like:

    PHP Code:
    if (isset($_GET['thread_id']))
    {
        
    $thread_id $_GET['thread_id'];
    }
    else
    {
        
    $thread_id auto_increment;

    I am coding this all assuming that the url of a post would be similar to vb and phpBBs.

    I'm doing this for the learning experience. I mean, I wanted to see how hard it would be to code a forum.

  2. #2
    Follow Me On Twitter: @djg gold trophysilver trophybronze trophy Dan Grossman's Avatar
    Join Date
    Aug 2000
    Location
    Philadephia, PA
    Posts
    20,578
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    SELECT MAX(post_thread_id) from the table, add one, and you have a new thread ID.

  3. #3
    SitePoint Enthusiast Hakaslak's Avatar
    Join Date
    Nov 2006
    Location
    Nowhere.
    Posts
    28
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    oh wow cool! this is perfect, Thanks bud.

  4. #4
    SitePoint Enthusiast Hakaslak's Avatar
    Join Date
    Nov 2006
    Location
    Nowhere.
    Posts
    28
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    $topic_id = (mysql_result(mysql_query("SELECT MAX(post_topic_id) FROM cms_posts"), 0'post_topic_id'));
    $topic_id++; 
    var_dump keeps saying bool(false), and echoing $topic_id gives 1...

    Did I do something wrong?

  5. #5
    Follow Me On Twitter: @djg gold trophysilver trophybronze trophy Dan Grossman's Avatar
    Join Date
    Aug 2000
    Location
    Philadephia, PA
    Posts
    20,578
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Hakaslak View Post
    PHP Code:
    $topic_id = (mysql_result(mysql_query("SELECT MAX(post_topic_id) FROM cms_posts"), 0'post_topic_id'));
    $topic_id++; 
    var_dump keeps saying bool(false), and echoing $topic_id gives 1...

    Did I do something wrong?
    The column will not be named "post_topic_id" since that's not what you selected.

    PHP Code:
    $topic_id mysql_result(mysql_query("SELECT MAX(post_topic_id) FROM cms_posts"), 0)++; 

  6. #6
    SitePoint Wizard silver trophy
    Join Date
    Mar 2006
    Posts
    6,132
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    $res mysql_query($sql) or die(mysql_error());
    $row mysql_fetch_assoc($res);
    print_r($row); 
    see your mistake now?

  7. #7
    SitePoint Enthusiast Hakaslak's Avatar
    Join Date
    Nov 2006
    Location
    Nowhere.
    Posts
    28
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    would it be MAX(post_topic_id)?

    yep it works with MAX(post_topic_id).

    Geez im dumb.

  8. #8
    Follow Me On Twitter: @djg gold trophysilver trophybronze trophy Dan Grossman's Avatar
    Join Date
    Aug 2000
    Location
    Philadephia, PA
    Posts
    20,578
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    You can just omit the third parameter to mysql_result() when the row contains only one column.

  9. #9
    SitePoint Enthusiast Hakaslak's Avatar
    Join Date
    Nov 2006
    Location
    Nowhere.
    Posts
    28
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ahh. thanks. I really should RTFM. Stop pestering you guys >_>


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
  •