vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB3 General Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=111)
-   -   Loops in templates (https://vborg.vbsupport.ru/showthread.php?t=133213)

aragorn_reborn 12-04-2006 03:45 PM

Loops in templates
 
I have to make a custom page which queries a database and gets say n rows.

I store the rows in an array.

Now, i have to display the contents of each row, one line for one row.

For this, i need to have a for loop in the template.

How do i do this?

I hope my question is clear.....

peterska2 12-04-2006 03:51 PM

You can't have a loop. What you need is a second template just containing the code required for the row and then call that template in the first template.

aragorn_reborn 12-08-2006 08:07 AM

How exactly?

Look at the following code

Code:

eval('print_output("' . fetch_template('template1') . '");');
$sql = $db->query_read("SELECT name FROM " . TABLE_PREFIX . "people"); 
while ($array = $db->fetch_array($sql))
{
        $name = $array["0"];
        eval('print_output("' . fetch_template('template_row') . '");');

eval('print_output("' . fetch_template('template2') . '");');

template 1 contains

Code:

$stylevar[htmldoctype]
<html dir="$stylevar[textdirection]" lang="$stylevar[languagecode]">
<head>
$headinclude
<title>$vboptions[bbtitle] - Submit Executive Summary for Mentoring</title>
</head>
<body>
$header

$navbar

<table class="tborder" cellpadding="$stylevar[cellpadding]" cellspacing="$stylevar[cellspacing]" border="0" width="100%" align="center">
<tr>
        <td class="tcat" colspan="2">Heading</td>
</tr>
<tr>
        <td class="alt1">Name: *</td>
<td class="alt1"><select name="name">

template_row is

Code:

<option name="$name">$name</option>
template2 is

Code:

</select></td></tr></table>
$footer

This doesnt work

Do i have to use $template_row in template1 ?? Please help!
Stuck at this thing for the last 2 days

Spiffware 12-08-2006 10:44 AM

he needs a foreach command i think.


All times are GMT. The time now is 10:06 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.00963 seconds
  • Memory Usage 1,714KB
  • 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
  • (4)bbcode_code_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (4)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