The Arcive of Official vBulletin Modifications Site.It is not a VB3 engine, just a parsed copy! |
|
#1
|
||||
|
||||
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); } Code:
{vb:raw title} {vb:raw id} |
#2
|
||||
|
||||
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.
|
#3
|
||||
|
||||
Quote:
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')); Code:
{vb:raw displayres.id} {vb:raw displayres.title} {vb:raw displayres.filename} |
#4
|
|||
|
|||
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. |
Благодарность от: | ||
Craigr |
#5
|
||||
|
||||
Quote:
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); 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. |
#6
|
||||
|
||||
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:
Then, indeed, do a vb:each in the template. |
#7
|
|||
|
|||
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).
|
#8
|
||||
|
||||
Ah, yes, of course, the old fashioned way As I said, weekend mode...
|
#9
|
||||
|
||||
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. |
#10
|
|||
|
|||
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).
|
|
|
X vBulletin 3.8.12 by vBS Debug Information | |
---|---|
|
|
More Information | |
Template Usage:
Phrase Groups Available:
|
Included Files:
Hooks Called:
|