Go Back   vb.org Archive > vBulletin 3 Discussion > vB3 General Discussions
FAQ Community Calendar Today's Posts Search

Reply
 
Thread Tools Display Modes
  #1  
Old 10-15-2004, 05:08 PM
MrNase MrNase is offline
 
Join Date: May 2003
Location: Germany
Posts: 670
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default forumdisplay.php just like cgtalk.com

Hello,

We discussed that topic a bit at vbulletin (http://www.vbulletin.com/forum/showthread.php?t=118083) and now I'd like to have something like that.

I don't think it's a large problem to display the thumbnail of an attached image on forumdisplay.php but Iam just searching for a way to randomly display an image.. Most of the threads have 3 or even more images (the members are using the threads to publish pictures) and i'd like to display them randomly. Is there a way to add this function directly to the query or do I need some special code to generate a random ID with which I can pull it of the database and display it.

Here's a basic SQL Query which wouldn't work (obviously ) but which should give you an impression of what I want:

SELECT random(id) FROM attachment WHERE threadid = $threadid LIMIT 1;

In this case there is more than just one result because there are 3 or more images attached to that thread but I just want to have one random entry out of the 3.


I hope you get what I mean and I hope you can help me
Reply With Quote
  #2  
Old 10-15-2004, 05:13 PM
Zachery's Avatar
Zachery Zachery is offline
 
Join Date: Jul 2002
Location: Ontario, Canada
Posts: 11,440
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by MrNase
Hello,

We discussed that topic a bit at vbulletin (http://www.vbulletin.com/forum/showthread.php?t=118083) and now I'd like to have something like that.

I don't think it's a large problem to display the thumbnail of an attached image on forumdisplay.php but Iam just searching for a way to randomly display an image.. Most of the threads have 3 or even more images (the members are using the threads to publish pictures) and i'd like to display them randomly. Is there a way to add this function directly to the query or do I need some special code to generate a random ID with which I can pull it of the database and display it.

Here's a basic SQL Query which wouldn't work (obviously ) but which should give you an impression of what I want:

SELECT random(id) FROM attachment WHERE threadid = $threadid LIMIT 1;

In this case there is more than just one result because there are 3 or more images attached to that thread but I just want to have one random entry out of the 3.


I hope you get what I mean and I hope you can help me
If you can capture the attachment id's of the new thread and store them in thread table when it gets submitted you should be able to elimate a query at least, i thnk
Reply With Quote
  #3  
Old 10-15-2004, 05:33 PM
MrNase MrNase is offline
 
Join Date: May 2003
Location: Germany
Posts: 670
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Well I think that query shouldn't be the hardest thing.. I would get the first post (postid) of any thread in this forum which has an attachment and then I try to find the attachments via the postid. If that attachment already has a thumbnail that thumbnail should be displayed

The question is: If I have more than one attachment in my database with the postid '5' how can I randomly choose between one of those with that postid so that I only get one randomly chosen attachment (despite the fact I may even have 3 or more attachments with the postid '5').
Reply With Quote
  #4  
Old 10-15-2004, 08:25 PM
AN-net's Avatar
AN-net AN-net is offline
 
Join Date: Dec 2003
Location: AnimationTalk.com
Posts: 2,367
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

if you want a random attachment that most likely it will require an extra query
Reply With Quote
  #5  
Old 10-16-2004, 10:04 AM
MrNase MrNase is offline
 
Join Date: May 2003
Location: Germany
Posts: 670
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Well, I finally managed it

Right now Iam using:
Code:
           			// Thumbnails
			if($foruminfo['forumid'] == '22') {
			
            $getpostids = $DB_site->query("SELECT postid from post WHERE threadid = $thread[threadid] LIMIT 1");
	 	    while ($getpostid = $DB_site->fetch_array($getpostids))
            {
	        $attachments = $DB_site->query("
			SELECT filename, attachmentid, IF(thumbnail_filesize > 0, 1, 0) AS hasthumbnail
			FROM " . TABLE_PREFIX . "attachment
			WHERE postid = $getpostid[postid]
	        ORDER BY rand() LIMIT 1
		    ");
		    
		    $attachment = $DB_site->fetch_array($attachments);
		    $attachmentid = $attachment['attachmentid'];
		    $hasthumbnail = $attachment['hasthumbnail'];
		    }
	        }
            // Thumbnails
for forumdisplay.php

but there's one little problem:
http://www.pagodentreff.de/diskussio...splay.php?f=22 displays must of the thumbnails correct but some of them only have this HTML code:
<img src="attachment.php?attachmentid=&amp;&stc=1&thumb =1" />

instead of

<img src="attachment.php?attachmentid=83&stc=1&thumb=1" />


How can that be!?
$attachmentid should be a number and not &amp; !?

Edit:
Some more information:
$hasthumbnail seems to be false for some reason.. But why? Those are normal thumbnails and the showthread.php displays them correct.
Reply With Quote
  #6  
Old 10-16-2004, 10:21 AM
Dean C's Avatar
Dean C Dean C is offline
 
Join Date: Jan 2002
Location: England
Posts: 9,071
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Also you have a query loop - very bad coding practice. You'd probably be better off either caching the info, or storing it in the thread table as zach said (probably more work - but far more efficient)
Reply With Quote
  #7  
Old 10-16-2004, 12:39 PM
AN-net's Avatar
AN-net AN-net is offline
 
Join Date: Dec 2003
Location: AnimationTalk.com
Posts: 2,367
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

i find storing data like last posts, entry counts, and other things better because its alot more work in the beginning but in the long run saves you alot of time and is more efficient
Reply With Quote
  #8  
Old 10-16-2004, 12:41 PM
MrNase MrNase is offline
 
Join Date: May 2003
Location: Germany
Posts: 670
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

What should be stored and how should it be stored?

The ids of any uploaded file in the threads table?
Reply With Quote
  #9  
Old 10-16-2004, 12:53 PM
Xenon's Avatar
Xenon Xenon is offline
 
Join Date: Oct 2001
Location: Bavaria
Posts: 12,878
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

well, to be exactly, it's not a real loop, as you are limiting the ammount of results to 1.

still that code would look better then:

PHP Code:
            // Thumbnails
            
if($foruminfo['forumid'] == 22 AND $getpostid $DB_site->query_first("
                SELECT postid from post WHERE threadid = 
$thread[threadid] LIMIT 1"))
            {
                    
$attachment $DB_site->query_first("
                    SELECT filename, attachmentid, IF(thumbnail_filesize > 0, 1, 0) AS hasthumbnail
                    FROM " 
TABLE_PREFIX "attachment
                    WHERE postid = 
$getpostid[postid]
                        ORDER BY rand() LIMIT 1
                    "
);
                    
$attachmentid $attachment['attachmentid'];
                    
$hasthumbnail $attachment['hasthumbnail'];
                }
                
// Thumbnails 
Reply With Quote
  #10  
Old 10-16-2004, 01:41 PM
MrNase MrNase is offline
 
Join Date: May 2003
Location: Germany
Posts: 670
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Thanks Stefan,

Hast einen gut bei mir
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 06:35 PM.


Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2024, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.04593 seconds
  • Memory Usage 2,269KB
  • Queries Executed 11 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)ad_showthread_beforeqr
  • (1)ad_showthread_firstpost
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (1)bbcode_code
  • (1)bbcode_php
  • (1)bbcode_quote
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (1)pagenav_pagelink
  • (10)post_thanks_box
  • (10)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (10)post_thanks_postbit_info
  • (10)postbit
  • (10)postbit_onlinestatus
  • (10)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available:
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files:
  • ./showthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_post_thanks.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • forumjump
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • fetch_musername
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • pagenav_page
  • pagenav_complete
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete