vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB3 Programming Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=15)
-   -   repeating an array from db in a template?? (https://vborg.vbsupport.ru/showthread.php?t=162040)

Jelmertjee 11-06-2007 09:18 AM

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!


All times are GMT. The time now is 12:39 AM.

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.01114 seconds
  • Memory Usage 1,740KB
  • 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
  • (1)bbcode_html_printable
  • (4)bbcode_php_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (1)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