Simple Question, from database into a table

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

So you have a template that has a variable in it, and you are trying to fill the variable with the data that you want shown? Is that right?
phelpsa
Forum Commoner
Posts: 48
Joined: Thu Feb 17, 2005 1:05 pm

Post by phelpsa »

That is right. It is for an UltimaBB Forum.

Adam
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

What template system do they use for that BB? I only ask because in my template engines, you assign a variable a value, then when the template is parsed, that variable gets parsed with the template and the value assigned to that variable gets displayed. I'd like to see the parsing process.
phelpsa
Forum Commoner
Posts: 48
Joined: Thu Feb 17, 2005 1:05 pm

Post by phelpsa »

I'm not 100% sure but the templates are stored in the database and then pulled into the script by an eval() function. Make any sense to you? It's all a strange language to me! :lol:
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

It makes sense, though it seems somewhat insecure to use eval() on data coming from the database mixed with input coming from the script.

What you want to do is grab all of your data that belongs in your var ($myvar for example) up front by appending the var with the data.

Code: Select all

<?php
$myvar = '';

for ($i = 0; $i < 30; $i++)
{
    $delim = ($i == 29) ? '' : ' grows into ';
    $myvar .= $i . $delim;
}

echo $myvar;
?>
In this example, the $delim is not the important thing. What is important is the dot operator ('.') that is used before the equal sign ('='). What this does is append the string you are assigning to the end of what is already in the variable. This essentially lets you grow the string until you are ready to output it.
Post Reply