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

Reply
 
Thread Tools Display Modes
  #1  
Old 08-02-2015, 08:26 AM
Bastien's Avatar
Bastien Bastien is offline
 
Join Date: May 2015
Location: France
Posts: 70
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default Display the result of a query in postbit

Hi all,

I'm wanting to display in the postbit, the result of a query but that doesn't work and I don't understand why.

So, this is my table fournisseurs : SC1
Here is where I want to display its phone number (alt of the img) : SC2

This is the hook I added for showpost_start :

PHP Code:
$fournisseur $vbulletin->db->query_first("
            SELECT telephone
            FROM devis_fournisseurs
WHERE userid=
$post[userid]  
"
);    

$telephone="$fournisseur[telephone]";

return 
$telephone

And this is the little part that displays the phone picture and should display the number, but it doesn't

Code:
<vb:if condition="$post[usergroupid]==10 || $post[usergroupid]==11">
<img src="images/smilies/telephone.png" alt="test {vb:raw telephone}"></vb:if>
Could someone give me some help ?
Thank you:up:
Attached Images
File Type: jpg 1.jpg (31.3 KB, 0 views)
File Type: jpg 2.jpg (67.5 KB, 0 views)
Reply With Quote
  #2  
Old 08-02-2015, 09:24 AM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

It's kind of tricky selecting hooks just based on the name. Anyway, I would use postbit_display_complete instead of showpost_start.

You don't want to return from your plugin, because that could keep other plugins on the same hook from running. What you want to do is register your variable to the postbit template. Here's an article on rendering templates: https://vborg.vbsupport.ru/showthread.php?t=228078

But your code would be something like:
PHP Code:
global $vbulletin;

$fournisseur $vbulletin->db->query_first(
            SELECT telephone 
            FROM devis_fournisseurs 
WHERE userid=
$post[userid]   
"
);     

vB_Template::preRegister('postbit', array('telephone' => $fournisseur[telephone])); 
You might also want to keep an array of userid => telephone and check that before doing a query, that way you won't have to query the same user more than once. Note that postbit_display_complete is called from inside a function, so you need to use a 'global' statement for any global variables you want to use.
Reply With Quote
  #3  
Old 08-03-2015, 07:05 AM
Bastien's Avatar
Bastien Bastien is offline
 
Join Date: May 2015
Location: France
Posts: 70
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by kh99 View Post
It's kind of tricky selecting hooks just based on the name. Anyway, I would use postbit_display_complete instead of showpost_start.

You don't want to return from your plugin, because that could keep other plugins on the same hook from running. What you want to do is register your variable to the postbit template. Here's an article on rendering templates: https://vborg.vbsupport.ru/showthread.php?t=228078

But your code would be something like:
PHP Code:
global $vbulletin;

$fournisseur $vbulletin->db->query_first(
            SELECT telephone 
            FROM devis_fournisseurs 
WHERE userid=
$post[userid]   
"
);     

vB_Template::preRegister('postbit', array('telephone' => $fournisseur[telephone])); 
You might also want to keep an array of userid => telephone and check that before doing a query, that way you won't have to query the same user more than once. Note that postbit_display_complete is called from inside a function, so you need to use a 'global' statement for any global variables you want to use.
Thank you kh, great article !

I had tried with preregister function, but had no success, so I tried the return with no more ...

I try again :up:

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

It works fine

Code:
global $vbulletin;

$fournisseur = $vbulletin->db->query_first(" 
            SELECT telephone 
            FROM devis_fournisseurs 
WHERE userid=$post[userid]   
");     

$telephone = $fournisseur[telephone];

vB_Template::preRegister('postbit_legacy', array('telephone' => $telephone));

But you said

Quote:
that way you won't have to query the same user more than once
Could ou help me with it ?

I tried recording in an array and check them with in_array but no success
Reply With Quote
  #4  
Old 08-03-2015, 08:48 AM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

What I meant is something like this:

PHP Code:
global $vbulletin$cache_telephone;

if (!isset(
$cache_telephone[$post['userid']]))
{
   
$fournisseur $vbulletin->db->query_first(
            SELECT telephone 
            FROM devis_fournisseurs 
   WHERE userid=
$post[userid] 
   "
);     
    if (
is_array($fournisseur))
   {
      
$cache_telephone[$post['userid']] = $fournisseur[telephone];
   }
}

if (isset(
$cache_telephone[$post['userid']]))
{
   
vB_Template::preRegister('postbit_legacy', array('telephone' => $cache_telephone[$post['userid']]));


But I remembered a better way that might work without adding a query. You can add on to the existing post query in showthread.php using a plugin on hook showthread_query_postids and code like this:
PHP Code:
$calc_found_rows .= ', devis_fournisseurs.telephone ';
$hook_query_joins .= ' LEFT JOIN devis_fournisseurs ON (devis_fournisseurs.userid = post.userid) '
That should put the telephone field in $post without the other plugin.
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 11:39 AM.


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.03816 seconds
  • Memory Usage 2,233KB
  • Queries Executed 12 (?)
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
  • (2)bbcode_code
  • (5)bbcode_php
  • (2)bbcode_quote
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (4)post_thanks_box
  • (4)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (4)post_thanks_postbit_info
  • (4)postbit
  • (2)postbit_attachment
  • (4)postbit_onlinestatus
  • (4)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_attachment
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete