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

Reply
 
Thread Tools Display Modes
  #1  
Old 11-25-2007, 08:26 AM
Defkalion Defkalion is offline
 
Join Date: Jan 2007
Location: Athens, Greece
Posts: 201
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default Where to include a new variable?

I have built an SQL query that returns the count of a user's topics in certain forums. I want to use this as a variable, so I can use it in my postbit templates.

The problem is I don't know how to do that.

The code I THINK I should use to define the variable with this SQL query is this;

$stories = $db->query_first("
SELECT
Count(vbthread.threadid)
FROM vbthread
WHERE
(vbthread.forumid = '57' OR
vbthread.forumid = '58' OR
vbthread.forumid = '59' OR
vbthread.forumid = '60' OR
vbthread.forumid = '61' OR
vbthread.forumid = '62' OR
vbthread.forumid = '63' ) AND
vbthread.postuserid = '$post[userid]'
");

1. Is this correct?
2. Where should I use this code to define the variable and then be able to use the $stories variable inside my postbit templates?
Reply With Quote
  #2  
Old 11-26-2007, 05:00 PM
Defkalion Defkalion is offline
 
Join Date: Jan 2007
Location: Athens, Greece
Posts: 201
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Can anyone please help on this ?
Reply With Quote
  #3  
Old 01-09-2008, 08:35 AM
Defkalion Defkalion is offline
 
Join Date: Jan 2007
Location: Athens, Greece
Posts: 201
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Ok I'm coming back on this, since I solved it - but partially;

I have created a plugin with this code;

PHP Code:
$stories $this->registry->db->query_first("
                    SELECT count(threadid) AS num
                    FROM vbthread AS thread
                    WHERE 
                       ( forumid = 57 or
                        forumid = 58 or
                        forumid = 59 or
                        forumid = 60 or
                        forumid = 61 or
                        forumid = 62 or
                        forumid = 63 ) and
                        postuserid = " 
$post['userid'] . "
"
); 
And then I use the variable $stories[num] inside my postbit template to display the result. This part is working fine.

But now I cannot use my external RSS forum feeds, I get a database error, saying that:

PHP Code:
Database error in vBulletin 3.6.8:

Invalid SQL:

                    
SELECT count(threadid) AS num
                    FROM vbthread 
AS thread
                    WHERE
                       
forumid 57 or
                        
forumid 58 or
                        
forumid 59 or
                        
forumid 60 or
                        
forumid 61 or
                        
forumid 62 or
                        
forumid 63 ) and
                        
postuserid =;

MySQL Error  You have an error in your SQL syntaxcheck the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 11
Error Number 
1064
Date         
WednesdayJanuary 9th 2008 12:29:11 PM
Script       
http://www.MYDOMAIN.COM/external.php??type=rss2&forumid=57
Referrer     :
IP Address   xxxx
Username     
not registered user
Classname    
vb_database 

I think this is because of the HOOK location I've put my plugin in. I put it in postbit_display_start. Is this correct? Should I choose another hook location?
Reply With Quote
  #4  
Old 01-09-2008, 02:20 PM
Opserty Opserty is offline
 
Join Date: Apr 2007
Posts: 4,103
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Have you tried $post['postuserid'] instead of just $post['userid'] maybe that will correct it?

Also you can just say this for your query:
[sql]
SELECT COUNT(threadid) AS num FROM vbthread WHERE forumid IN (57, 58, 59..., 63) AND postuserid = $post['postuserid'][/sql]

Finally remember you are running a query on every postbit on every showthread so you may want to rethink what you are doing. You may be able to modify the showthread query using the showthread_query hook and add a join/count to the query.
Reply With Quote
  #5  
Old 01-09-2008, 02:55 PM
ZomgStuff ZomgStuff is offline
 
Join Date: Feb 2007
Posts: 469
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
postuserid =;
?



.
Reply With Quote
  #6  
Old 01-09-2008, 04:16 PM
Defkalion Defkalion is offline
 
Join Date: Jan 2007
Location: Athens, Greece
Posts: 201
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Thankyou so much for your reply.

Quote:
Originally Posted by Opserty View Post
Have you tried $post['postuserid'] instead of just $post['userid'] maybe that will correct it?
I tried but this produced an SQL error whenever I tried to view any topic.


Quote:
Originally Posted by Opserty View Post
Also you can just say this for your query:
[sql]
SELECT COUNT(threadid) AS num FROM vbthread WHERE forumid IN (57, 58, 59..., 63) AND postuserid = $post['postuserid'][/sql]
This produced the same SQL error as the above.


Quote:
Originally Posted by Opserty View Post
Finally remember you are running a query on every postbit on every showthread so you may want to rethink what you are doing. You may be able to modify the showthread query using the showthread_query hook and add a join/count to the query.
I know and you are correct, but I do not know how to make this work in any other way. Thankyou for your suggestion but I cannot implement this without some help. You mean I should use the same query but insert it at the showthread_query hook? What do you mean add a join/count to the query?

Anyway my website is not that big so I don't have performance issues with this hack, so even if I could correct this problem with my RSS feeds I would keep it in the postbit.

Any other ideas?

Thankyou for your time.
Regards.

--------------- Added [DATE]1199918887[/DATE] at [TIME]1199918887[/TIME] ---------------

Ok someone else helped me, the solution is here:

http://www.vbnova.com/showthread.php?p=7259#post7259

Thanks for taking the time to read this.
Reply With Quote
  #7  
Old 05-13-2008, 08:28 AM
Defkalion Defkalion is offline
 
Join Date: Jan 2007
Location: Athens, Greece
Posts: 201
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Ok I'm re-surfacing this thread because I need some help.

I have created a plugin in the Postbit_display_start hook with this code;

PHP Code:
$stories $this->registry->db->query_first("
                    SELECT count(threadid) AS num
                    FROM vbthread AS thread
                    WHERE 
                       ( forumid = 57 or
                        forumid = 58 or
                        forumid = 59 or
                        forumid = 60 or
                        forumid = 61 or
                        forumid = 62 or
                        forumid = 63 ) and
                        postuserid = " 
$post['userid'] . "
"
); 
And then I use the variable $stories[num] inside my postbit template to display the result (the result is all the threads a user has started in specific forums). This part is working fine (I only have a small forum so no delay problems)

The thing is, I want to display the same information in the MEMBERINFO page, anyone know how to do that? I suppose I have to add the variable to another hook as well?
Reply With Quote
  #8  
Old 05-14-2008, 07:45 AM
GameWizard's Avatar
GameWizard GameWizard is offline
 
Join Date: Apr 2004
Location: Vancouver, BC
Posts: 319
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I believe the hook for the member profiles would be member_complete
Reply With Quote
  #9  
Old 05-14-2008, 10:59 AM
Opserty Opserty is offline
 
Join Date: Apr 2007
Posts: 4,103
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

By the way, you can shorten your SQL command by using the [minicode]WHERE forumid IN (57, 58, ...63)[/minicode]

Even though the other bit in my previous post may not have worked, the SQL I posted on the line above will.
Reply With Quote
  #10  
Old 05-14-2008, 08:46 PM
Defkalion Defkalion is offline
 
Join Date: Jan 2007
Location: Athens, Greece
Posts: 201
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Thanks fellows for your help.

GameWizard, I tried copying the plugin and using it to the member_complete hook and didn't work. I also tried using the member_start hook, but again no go.

I think I also have to change the last part of the code where it says

Quote:
postuserid = " . $post['userid'] . "
because that one was used in the postbit, so shouldn't I change that to something like

Quote:
postuserid = " . $userinfo['userid'] . "
so that it works in member profile page, or am I doing silly things?
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:00 PM.


Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.04159 seconds
  • Memory Usage 2,282KB
  • 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
  • (3)bbcode_php
  • (6)bbcode_quote
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (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
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete