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 01-22-2005, 03:18 AM
TheMayhem's Avatar
TheMayhem TheMayhem is offline
 
Join Date: Oct 2002
Location: Pittsburgh, Pa
Posts: 526
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default 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?
Reply With Quote
  #2  
Old 01-22-2005, 03:21 AM
Andreas's Avatar
Andreas Andreas is offline
 
Join Date: Jan 2004
Location: Germany
Posts: 6,863
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

You muste evaluate templates to get the variables in:

PHP Code:
eval('$template = "' fetch_template('templatenamer') . '";'); 
Reply With Quote
  #3  
Old 01-22-2005, 03:23 AM
noppid noppid is offline
 
Join Date: Mar 2003
Location: Florida
Posts: 1,875
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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.
Reply With Quote
  #4  
Old 01-22-2005, 03:27 AM
TheMayhem's Avatar
TheMayhem TheMayhem is offline
 
Join Date: Oct 2002
Location: Pittsburgh, Pa
Posts: 526
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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
Reply With Quote
  #5  
Old 01-22-2005, 03:40 AM
Andreas's Avatar
Andreas Andreas is offline
 
Join Date: Jan 2004
Location: Germany
Posts: 6,863
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

PHP Code:
$compiled_header_template str_replace('\\\\$''\\$'addslashes($templates['header']));
eval(
'$header = "' $compiled_header_template '";');
echo 
$header
Reply With Quote
  #6  
Old 01-22-2005, 04:08 AM
TheMayhem's Avatar
TheMayhem TheMayhem is offline
 
Join Date: Oct 2002
Location: Pittsburgh, Pa
Posts: 526
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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?
Reply With Quote
  #7  
Old 01-22-2005, 04:12 AM
Andreas's Avatar
Andreas Andreas is offline
 
Join Date: Jan 2004
Location: Germany
Posts: 6,863
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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.
Reply With Quote
  #8  
Old 01-22-2005, 02:06 PM
TheMayhem's Avatar
TheMayhem TheMayhem is offline
 
Join Date: Oct 2002
Location: Pittsburgh, Pa
Posts: 526
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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?
Reply With Quote
  #9  
Old 01-22-2005, 02:09 PM
Andreas's Avatar
Andreas Andreas is offline
 
Join Date: Jan 2004
Location: Germany
Posts: 6,863
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

The code seems to be OK.
Can you post a template that does not work?
Reply With Quote
  #10  
Old 01-22-2005, 02:26 PM
TheMayhem's Avatar
TheMayhem TheMayhem is offline
 
Join Date: Oct 2002
Location: Pittsburgh, Pa
Posts: 526
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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
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:49 PM.


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.04486 seconds
  • Memory Usage 2,273KB
  • 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
  • (7)bbcode_php
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (2)pagenav_pagelink
  • (10)post_thanks_box
  • (10)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (10)post_thanks_postbit_info
  • (10)postbit
  • (10)postbit_onlinestatus
  • (10)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_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
  • pagenav_page
  • pagenav_complete
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete