Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New Coder
    Join Date
    Dec 2002
    Location
    Misawa, Japan
    Posts
    45
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Post Query to phpbb2 db

    This is a simple question. Specifically, how would I query a phpbb2 database to print the most recent post in an external php page?

  • #2
    New Coder
    Join Date
    Dec 2002
    Location
    Misawa, Japan
    Posts
    45
    Thanks
    0
    Thanked 0 Times in 0 Posts
    This is the code I have so far:

    <?php

    $db = mysql_connect("localhost", "root");

    mysql_select_db("mydb",$db);

    $result = mysql_query("SELECT * FROM ?????",$db);

    printf("Author: %s<br>\n", mysql_result($result,0,"????"));
    printf("Title: %s<br>\n", mysql_result($result,0,"????"));
    printf("Date: %s<br>\n", mysql_result($result,0,"????"));

    ?>


    I am not sure how to print the author, date and title as I do not know what they called. The phpbb2 board was installed by another man.

  • #3
    New Coder
    Join Date
    Jun 2004
    Location
    Newcastle, England
    Posts
    72
    Thanks
    0
    Thanked 0 Times in 0 Posts
    ok here is what ive found concerning this:

    2 tables: phpbb_posts and phpbb_posts_text. Altho the prefix is set at installation, but that is the default. I think you can get the most recent post by just getting the highest post_id(which is in both tables).

    Title is in phpbb_posts_text as column name post_subject.
    Date is a timestamp(think its not a mysql form, already unix form) in phpbb_posts, column name post_time.

    The authors user id is in phpbb_posts as poster_id. You can find out the username by using table phpbb_users and checking the user_id column. The username is stored in username in phpbb_users.

    Hope all this helps!!

  • #4
    New Coder
    Join Date
    Jun 2004
    Location
    Newcastle, England
    Posts
    72
    Thanks
    0
    Thanked 0 Times in 0 Posts
    My code for this:


    $query = "SELECT u.username, t.post_subject, p.post_time FROM phpbb_users u, phpbb_posts p, phpbb_posts_text t WHERE MAX(p.post_id) AND p.poster_id = u.user_id ;

    $results=mysql_query($query);

    Then use date() to convert the timestamp etc etc and format as required.

    You could also search for the maximum timestamp in p.post_time, this would also give the latest post.

    I'm not great at SQL so some of that query might be wrong, especially perhaps the MAX part...but everything up to the WHERE is correct at least, for def
    Beauty is in the eye of the beer-holder

    Man who smoke pot, choke on handle


  •  

    Posting Permissions

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