vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB3 Programming Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=15)
-   -   What way could I do this (https://vborg.vbsupport.ru/showthread.php?t=74856)

TheMayhem 01-22-2005 03:18 AM

What way could I do this
 
I was just wondering I have all of these arrays such as $user[name]; Now what my problem is I have a repeating loop that gets a few templates that I store in the database. Don't ask why I just want them their for what I'm trying to learn. My problem is whenever I loop and echo, some of those templates will call upon stuff like $user[name] and it should output a text of like Joe for example... instead it only ouputs the actual text of $user[name].

Hopefully I'm not confusing anyone, but is there a way that if you define something in a file and then run a query if the query has any information on the echo statement of whats stored inside such as an array or variable that on the output it would display what it has been defined too?

Andreas 01-22-2005 03:21 AM

You muste evaluate templates to get the variables in:

PHP Code:

eval('$template = "' fetch_template('templatenamer') . '";'); 


noppid 01-22-2005 03:23 AM

Look at the code at the top of every vB file, see a pattern? Especially this...

PHP Code:

require_once('./global.php'); 

$bbuserinfo comes from there and is an array with all of the current user's vb info if I understand correctly. I do not have a list of what's in there. There may be one at vb.com.

yeah, and what he said too.

TheMayhem 01-22-2005 03:27 AM

So lets say I had something like this...

PHP Code:

$result mysql_query('SELECT * FROM templates'); 
while (
$row mysql_fetch_assoc($result)) 

    
$templates[$row['name']] = $row['template'];     


echo 
$templates['header']; 
echo 
$templates['index']; 

How would I complete the transformation? Btw noppid this isn't for a vb, I'm just trying to learn PHP by creating a complex news program

Andreas 01-22-2005 03:40 AM

PHP Code:

$compiled_header_template str_replace('\\\\$''\\$'addslashes($templates['header']));
eval(
'$header = "' $compiled_header_template '";');
echo 
$header


TheMayhem 01-22-2005 04:08 AM

There's a few problems that arise when I do that... It now retrieves the data but at the same time when it does, it now won't let me do like set widths for tables or to be able to call upon any CSS such as the class = to whatever and so forth... Any ways around that one?

Andreas 01-22-2005 04:12 AM

Hmm ...

PHP Code:

<?php
 $foobar 
'Foo Bar';
 
$templates['header'] = '<table width="100%" class="mytable"><tr><td>$foobar</td></tr></table>';
 
$compiled_header_template str_replace('\\\\$''\\$'addslashes($templates['header']));
 eval(
'$header = "' $compiled_header_template '";');
 echo 
$header
?>

Output
HTML Code:

<table width="100%" class="mytable"><tr><td>Foo Bar</td></tr></table>
Seems to work for me.

TheMayhem 01-22-2005 02:06 PM

I've triple checked this and something is definately wrong with this... This is my entire php code for anything retaining towards the templates.

PHP Code:

$result mysql_query('SELECT * FROM templates'); 
while (
$row mysql_fetch_assoc($result)) 

    
$templates[$row['name']] = $row['template'];     



// echo $templates['header']; 


$compiled_header_template str_replace('\\\\$''\\$'addslashes($templates['header'])); 
eval(
'$header = "' $compiled_header_template '";'); 
echo 
$header

If I just echo the $header template without doing any of the str_replace functions and so forth.... The css will work, the set table widths, and so forth will work, BUT any variables or arrays that I output wont. I can use your way and get most of the variables and arrays to ouput but then it will not accept the CSS properly nor the set table widths, heights, and so forth. Any idea on what could possibly be the problem?

Andreas 01-22-2005 02:09 PM

The code seems to be OK.
Can you post a template that does not work?

TheMayhem 01-22-2005 02:26 PM

PHP Code:

<body bgcolor='#ffffff' leftmargin='0' topmargin='0' bottommargin='0' rightmargin='0'>
<
table cellpadding='0' cellspacing='0' border='0' class='maintable' width='650' align='center'>
<
tr>
<
td>LOGO GOES HERE</td>
</
tr>
<
tr>
<
td background='images/navbg.jpg' height='20'>LINKS</td>
</
tr>
<
tr>
<
td

This is the header template that doesnt even call upon any arrays. I have it after all the php code at the bottom of the page right before the last } ?> and even this one will not cooperate


All times are GMT. The time now is 02:42 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.01044 seconds
  • Memory Usage 1,753KB
  • 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
  • (7)bbcode_php_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (2)pagenav_pagelink
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (10)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
  • pagenav_page
  • pagenav_complete
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete