SitePoint Sponsor

User Tag List

Results 1 to 23 of 23
  1. #1
    Rocket Scientist
    Join Date
    Jun 2003
    Location
    Manchester, UK
    Posts
    300
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question PHP and vBulletin help

    I have tried posting this on vBulletin.org to no avail, and I have been working on it for a week with my uber simplistic knowledge, with no luck! So any help would be appreciated

    Basically, I would like that in a forum section such as : http://www.pcreview.co.uk/reviews.php?forumid=22 I would see the attachment of the first post in a thread next to the article name. I would basically need the "postid" of the first post in each thread to get this to work.

    Any ideas?

  2. #2
    Non-Member Icheb's Avatar
    Join Date
    Mar 2003
    Location
    Germany
    Posts
    1,474
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Question is: What is given? The threadid, the title or what?

    If you have the threadid, you sort the posts by "postdate" in an ascending order with LIMIT 1, so you only get the first post from the thread. Then you could use vB's built-in function to display the image (the attachment).

    If you only have the title it's going to be a bit more complicated, since vB doesn't have an index on the title column per default, so searching by title would take a relative enormous amount on larger forums and I wouldn't suggest adding an index.

  3. #3
    Rocket Scientist
    Join Date
    Jun 2003
    Location
    Manchester, UK
    Posts
    300
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yep, I have the thread id of each post. Do you know what the query would be, as I am only a real PHP novice!

  4. #4
    Non-Member Icheb's Avatar
    Join Date
    Mar 2003
    Location
    Germany
    Posts
    1,474
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    With vBulletin 2:

    PHP Code:
    SELECT postid FROM post WHERE threadid=<your threadid hereORDER BY dateline ASC LIMIT 1 
    However, with vBulletin 3 it would be a lot easier:

    PHP Code:
    SELECT firstpostid FROM thread WHERE threadid=<your threadid here
    I haven't tested this though, so don't hesitate to ask if it doesn't work .

  5. #5
    Rocket Scientist
    Join Date
    Jun 2003
    Location
    Manchester, UK
    Posts
    300
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Cheers Mate! Will give it a try tonight!

  6. #6
    Rocket Scientist
    Join Date
    Jun 2003
    Location
    Manchester, UK
    Posts
    300
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    OK - its vB 2.2.2

    Where abouts would I add that query? I guess it would have to be in forumdisplay.php for where I would want to use it. I would like the get the image from the first post to appear next to that threads title. I can get the templates sorted out, but I cant figure out where to put the query!

    Thanks so much for your help!

  7. #7
    Non-Member Icheb's Avatar
    Join Date
    Mar 2003
    Location
    Germany
    Posts
    1,474
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Forumdisplay.php is right. After you got the post id, you can display the image using

    HTML Code:
    <img src="http://<your forum's url>/attachment.php?postid=<post id>">

  8. #8
    Rocket Scientist
    Join Date
    Jun 2003
    Location
    Manchester, UK
    Posts
    300
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Sorry for all the questions, but where exactly do I put the PHP?

  9. #9
    Rocket Scientist
    Join Date
    Jun 2003
    Location
    Manchester, UK
    Posts
    300
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    anyone?

  10. #10
    Rocket Scientist
    Join Date
    Jun 2003
    Location
    Manchester, UK
    Posts
    300
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    still no luck

  11. #11
    + platinum's Avatar
    Join Date
    Jun 2001
    Location
    Adelaide, Australia
    Posts
    6,441
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    didn't you say you needed it in forumdisplay.php? You should be able to use it in there...

  12. #12
    Rocket Scientist
    Join Date
    Jun 2003
    Location
    Manchester, UK
    Posts
    300
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by platinum
    didn't you say you needed it in forumdisplay.php? You should be able to use it in there...
    I'm not sure where to put it though, and how to call it - I'm not too good with this sort of stuff

  13. #13
    Non-Member Icheb's Avatar
    Join Date
    Mar 2003
    Location
    Germany
    Posts
    1,474
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I didn't test this, so don't bother blaming me when it's wrong:

    Open forumdisplay.php and search for the while-loop which outputs the thread information. I think it's this one, but I am not sure:

    PHP Code:
    while ($thread=$DB_site->fetch_array($threads)) { 
    Then, insert the query I specified in post #4 below that line to get the id of the first post. Just dig a bit to get the variable you need for the threadid.

    Now, put this code

    HTML Code:
    <img src="attachment.php?postid=<post id>">
    into a variable and put the variable into the template "forumdisplaybit", where you want the image to be displayed.

    However, I strongly advise against what you are trying to do. It needs one query per thread, which is really not recommended.

  14. #14
    Rocket Scientist
    Join Date
    Jun 2003
    Location
    Manchester, UK
    Posts
    300
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I have added:

    $postpic=$DB_site->query('SELECT postid FROM post WHERE threadid=$threadids ORDER BY dateline ASC LIMIT 1');

    to that line, but it gives me errors? Any ideas? I will keep working on it, as I should be able to figure something out!

  15. #15
    Non-Member Icheb's Avatar
    Join Date
    Mar 2003
    Location
    Germany
    Posts
    1,474
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It's $thread[threadid], not $threadids...

    And you should post the error message next time.

  16. #16
    Rocket Scientist
    Join Date
    Jun 2003
    Location
    Manchester, UK
    Posts
    300
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I also tried that and got "Parse error: parse error in /home/pcreview/public_html/reviews.php on line 476"

    when using $postpic=$DB_site->query('SELECT postid FROM post WHERE threadid='$thread[threadid]' ORDER BY dateline ASC LIMIT 1');

  17. #17
    Non-Member Icheb's Avatar
    Join Date
    Mar 2003
    Location
    Germany
    Posts
    1,474
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    That's because you use single quotes around the query and around the threadid.

    Do this:

    PHP Code:
    $postpic=$DB_site->query('SELECT postid FROM post WHERE threadid='$thread[threadid] .' ORDER BY dateline ASC LIMIT 1'); 
    For numerical values it is recommended to not use quotes at all and when using arrays, you should "jump out" and "jump back in" as I showed you above (the dot is a string concatenation character).

  18. #18
    Rocket Scientist
    Join Date
    Jun 2003
    Location
    Manchester, UK
    Posts
    300
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    OK, thanks - trying now

  19. #19
    Rocket Scientist
    Join Date
    Jun 2003
    Location
    Manchester, UK
    Posts
    300
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    $postpic give a result similar to "Resource id #41" when used in a template?

  20. #20
    Non-Member Icheb's Avatar
    Join Date
    Mar 2003
    Location
    Germany
    Posts
    1,474
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    $postpics=$DB_site->query('the query');
    while(
    $postpic=mysql_fetch_array($postpics)) {
    $postid=$postpic['postid']

    Now you can use $postid for the id.

  21. #21
    Rocket Scientist
    Join Date
    Jun 2003
    Location
    Manchester, UK
    Posts
    300
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Now I get "Parse error: parse error in /home/pcreview/public_html/reviews.php on line 480" where line 480 is the "}"

    using:

    $postpics=$DB_site->query('SELECT postid FROM post WHERE threadid='. $thread[threadid] .' ORDER BY dateline ASC LIMIT 1');
    while($postpic=mysql_fetch_array($postpics)) {
    $postid=$postpic['postid']
    }

  22. #22
    Non-Member Icheb's Avatar
    Join Date
    Mar 2003
    Location
    Germany
    Posts
    1,474
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Sorry, forgot the semicolon:

    $postid=$postpic['postid'];

  23. #23
    Rocket Scientist
    Join Date
    Jun 2003
    Location
    Manchester, UK
    Posts
    300
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    IT WORKS!!!!!

    Thank you so much!


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
  •