vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB3 Programming Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=15)
-   -   Where to include a new variable? (https://vborg.vbsupport.ru/showthread.php?t=163563)

Defkalion 11-25-2007 08:26 AM

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?

Defkalion 11-26-2007 05:00 PM

Can anyone please help on this ?

Defkalion 01-09-2008 08:35 AM

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?

Opserty 01-09-2008 02:20 PM

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.

ZomgStuff 01-09-2008 02:55 PM

Quote:

postuserid =;
?



.

Defkalion 01-09-2008 04:16 PM

Thankyou so much for your reply.

Quote:

Originally Posted by Opserty (Post 1418379)
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 (Post 1418379)
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 (Post 1418379)
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. :o

--------------- 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.

Defkalion 05-13-2008 08:28 AM

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?

GameWizard 05-14-2008 07:45 AM

I believe the hook for the member profiles would be member_complete

Opserty 05-14-2008 10:59 AM

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.

Defkalion 05-14-2008 08:46 PM

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?


All times are GMT. The time now is 11:40 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.01318 seconds
  • Memory Usage 1,764KB
  • Queries Executed 10 (?)
More Information
Template Usage:
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (3)bbcode_php_printable
  • (6)bbcode_quote_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (10)printthreadbit
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • showthread
Included Files:
  • ./printthread.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/class_bbcode_alt.php
  • ./includes/class_bbcode.php
  • ./includes/functions_bigthree.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
  • printthread_start
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete