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-06-2007, 09:18 AM
Jelmertjee Jelmertjee is offline
 
Join Date: Oct 2006
Posts: 47
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default repeating an array from db in a template??

I'm creating a simple news mod for my site but I'm having some problems.. I can access the database and get the threads I need, but don't know how to repeat them in a template (eg. using a similar technique as $threadbits, $adv_portal_newsbits). Here's the code:

PHP Code:
// get main news page templates and data
if(!isset($_GET['do'])) 
{
    
$news_limit 10;
    
$news_forumid 15;
    
$news_ids = array();
    
    
$get_news_ids $db->query_read("
        SELECT threadid, firstpostid, dateline FROM " 
TABLE_PREFIX "thread
        WHERE visible = 1
        AND forumid = " 
$news_forumid "
        ORDER BY dateline DESC
        LIMIT 10
    "
);

    while (
$db_ids $db->fetch_array($get_news_ids))
    {
        
$news_ids[] = $db_ids['threadid'];
    }

    
$get_news $db->query_read("SELECT threadid, title, firstpostid, forumid, replycount, postusername, dateline
        FROM " 
TABLE_PREFIX "thread
        WHERE threadid IN("
implode(','$news_ids) .")
        ORDER BY dateline
    "
);  
    
    
$newscount 0;    
      
    while (
$db_array $db->fetch_array($get_news)) 
    {
        
$newscount++;
        
$news['title'] = $db_array['title'];
        
$news['username'] = $db_array['postusername'];
        
$news['replycount'] = $db_array['replycount'];
        eval(
'$news_bits = "' fetch_template('news_bits') . '";');
    }
     eval(
'print_output("' fetch_template('news_main') . '");');

in the main template I add the $news_bits variable, it does work but only shows the info for one thread.

the news_bits template contains:
HTML Code:
title: $news[title]<br />
author: $news[username]<br />
replies: $news[replycount]<br />
I think this shouldn't be too hard to solve, I just don't know how to go about it, any help is appreciated.

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

I've done some basic testing, and if I use echo it does work, but of course that's not what i'm after, here's the "working" code:

PHP Code:
while ($db_array $db->fetch_array($get_news)) 
    {
        
$newscount++;
        
$news['title'] = $db_array['title'];
        
$news['username'] = $db_array['postusername'];
        
$news['replycount'] = $db_array['replycount'];
        echo 
$news['title'];
    } 
this just provides an empty page with the thread titles of course, but does show the mysql works properly.

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

I've managed to fix the problem by using some code from this article, instead of using:

PHP Code:
eval('$news_bits = "' fetch_template('news_bits') . '";'); 
I used:
PHP Code:
eval('$news_bits .= "' fetch_template('news_bits') . '";'); 
.= instead of = so the array is added each time instead of being replaced, duh!
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 05:16 PM.


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.07413 seconds
  • Memory Usage 2,186KB
  • 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
  • (1)bbcode_html
  • (4)bbcode_php
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (1)post_thanks_box
  • (1)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (1)post_thanks_postbit_info
  • (1)postbit
  • (1)postbit_onlinestatus
  • (1)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
  • 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