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 07-21-2012, 11:49 AM
Craigr's Avatar
Craigr Craigr is offline
 
Join Date: May 2002
Location: Ayr, Scotland
Posts: 194
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default Plugin Query?

At the moment i have this as a plugin, it shows the first result ok, but sometimes i have more than 1 result and the rest are not appearing, any help appreciated:

Code:
$image = $vbulletin->db->query("SELECT * FROM ".TABLE_PREFIX."dbtech_gallery_images WHERE roll_id = '$threadid'");
    while ($row = $vbulletin->db->fetch_array($image))
    {
          $id = $row['imageid'];
          $title = $row['title'];

$templater = vB_Template::create('test');
$templater->register('id', $id);
$templater->register('title', $title);
$templatevalues['my_insertvar'] .= $templater->render();
vB_Template::preRegister('SHOWTHREAD', $templatevalues);
    }
my template called test:
Code:
{vb:raw title} {vb:raw id}
Reply With Quote
  #2  
Old 07-21-2012, 12:35 PM
cellarius's Avatar
cellarius cellarius is offline
 
Join Date: Aug 2005
Posts: 1,987
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

You're overwriting results with every while loop. Get the template stuff out of the while loop, and make sure your variable does not get overwritten (save the results into an array, for example.
Reply With Quote
  #3  
Old 07-21-2012, 01:01 PM
Craigr's Avatar
Craigr Craigr is offline
 
Join Date: May 2002
Location: Ayr, Scotland
Posts: 194
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by cellarius View Post
You're overwriting results with every while loop. Get the template stuff out of the while loop, and make sure your variable does not get overwritten (save the results into an array, for example.
Thanks the above does seem to work, but as you said i suspected i had the coding done wrong.

Sorry i am a newbie with vBulletin coding as you can see and am trying to convert my old site so it works pretty much the same.

I have edited my my code to look like this, but nothing appears:
Code:
$image = $vbulletin->db->query("SELECT * FROM ".TABLE_PREFIX."dbtech_gallery_images WHERE roll_id = '$threadid'");
    while ($row = $vbulletin->db->fetch_array($image))
    {
$imageresults = array();
$imageresults['imageid'] = $row['imageid'];
$imageresults['title'] = $row['title'];
$imageresults['filename'] = $row['filename']; 
    }

$templater = vB_Template::create('test');
$templater->register('displayres', $imageresults);
$templatevalues['my_insertvar'] .= $templater->render();
vB_Template::preRegister('SHOWTHREAD', array('$templatevalues'));
AND IN test TEMPLATE:
Code:
{vb:raw displayres.id} 
{vb:raw displayres.title}
{vb:raw displayres.filename}
Reply With Quote
  #4  
Old 07-21-2012, 01:09 PM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Are you trying to display one image or multiple images? If it's multiple images (Edit: and I reread your first post and I see now that's what the issue is), I think your original code was closer to being correct, you only need to move the preRegister call out of the loop.

Another way to do the same thing would be to collect up the rows in an array of arrays, then use vb:each in the template (which maybe is what cellarius was thinking). But it should work the way you have it.
Reply With Quote
Благодарность от:
Craigr
  #5  
Old 07-21-2012, 01:17 PM
Craigr's Avatar
Craigr Craigr is offline
 
Join Date: May 2002
Location: Ayr, Scotland
Posts: 194
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by kh99 View Post
Are you trying to display one image or multiple images? If it's multiple images (Edit: and I reread you first post and I see now that's what the issue is), I think your original code was closer to being correct, you only need to move the preRegsiter call out of the loop.

Another way to do the same thing would be to collect up the rows in an array of arrays, then use vb:each in the template (which maybe is what cellarius was thinking). But it should work the way you have it.
Code:
$image = $vbulletin->db->query("SELECT * FROM ".TABLE_PREFIX."dbtech_gallery_images WHERE roll_id = '$threadid'");
    while ($row = $vbulletin->db->fetch_array($image))
    {
          $id = $row['imageid'];
          $title = $row['title'];

$templater = vB_Template::create('test');
$templater->register('id', $id);
$templater->register('title', $title);
$templatevalues['my_insertvar'] .= $templater->render();
    }
vB_Template::preRegister('SHOWTHREAD', $templatevalues);
Is this better? It seems to display the results.

Not sure how i would convert the results into an array? Could you give me a short example how i would make it like that so i could follow that procedure in future, have looked at loads of examples on the site here, but cannot for the life of me get it working.
Reply With Quote
  #6  
Old 07-21-2012, 01:19 PM
cellarius's Avatar
cellarius cellarius is offline
 
Join Date: Aug 2005
Posts: 1,987
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I may be in weekend mode, but how would showing multiple images work with the first code given? $id and $tile would always end up being the values of the last element (i.e. they'd be overwritten with every loop).

For the second try in #3: Still the results are overwritten with every loop. Try something like that:
PHP Code:
$imageresults = array();
$imageresults['imageid'] = $row['imageid'];
$imageresults['imageid']['title'] = $row['title'];
$imageresults['imageid]['filename'] = $row['filename']; 
The imageid in the multidimensinal array keeps the values from being overwritten.

Then, indeed, do a vb:each in the template.
Reply With Quote
  #7  
Old 07-21-2012, 01:22 PM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by cellarius View Post
I may be in weekend mode, but how would showing multiple images work with the first code given? $id and $tile would always end up being the values of the last element (i.e. they'd be overwritten with every loop).
Well, I think because the 'test' template is being rendered each time, it doesn't matter if $id and $title are reused (unless I'm missing something).
Reply With Quote
  #8  
Old 07-21-2012, 01:33 PM
cellarius's Avatar
cellarius cellarius is offline
 
Join Date: Aug 2005
Posts: 1,987
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Ah, yes, of course, the old fashioned way As I said, weekend mode...
Reply With Quote
  #9  
Old 07-21-2012, 01:47 PM
Craigr's Avatar
Craigr Craigr is offline
 
Join Date: May 2002
Location: Ayr, Scotland
Posts: 194
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Cool thanks for all your help kh99 and cellarius, tried to like your post cellarius, but it appears i have liked too many of them already.

I will go ahead and use post 5 as it seems less complicated for me. Would like to work out arrays in the future.
Reply With Quote
  #10  
Old 07-21-2012, 02:22 PM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

There's a small example of how to use vb:each in the vbulletin manual: https://www.vbulletin.com/docs/html/...mplates_syntax (it's near the bottom).
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 12:45 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.11199 seconds
  • Memory Usage 2,274KB
  • Queries Executed 13 (?)
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
  • (5)bbcode_code
  • (1)bbcode_php
  • (3)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
  • (1)post_thanks_box_bit
  • (10)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (1)post_thanks_postbit
  • (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_postinfo_query
  • fetch_postinfo
  • 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
  • fetch_musername
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • post_thanks_function_fetch_thanks_bit_start
  • post_thanks_function_show_thanks_date_start
  • post_thanks_function_show_thanks_date_end
  • post_thanks_function_fetch_thanks_bit_end
  • post_thanks_function_fetch_post_thanks_template_start
  • post_thanks_function_fetch_post_thanks_template_end
  • pagenav_page
  • pagenav_complete
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete