PDA

View Full Version : Help with queries / eval() / templates


Oreamnos
05-30-2005, 12:26 AM
I am writing some of my own pages and have a simple question regarding the interaction of the script and the templates.

i have this on test.php
// Get some really valuable highly sought after information
$sql = $DB_site->query("
SELECT * FROM " . TABLE_PREFIX . "table_name"
);

while ($row = $DB_site->fetch_array($sql)) {

eval('$not_sure_what_this_is .= "' . fetch_template('MY_TEMPLATE') . '";');

}

and my template is basically
<tr>
<td>$row[field1]</td>
<td>$row[field2]</td>
</tr>

so when the template is called the variables such as $row[field1] are printed to the page. But what is $not_sure_what_this_is? What does it do? Where can I use it? Is it necessary?

Thanks,
eric

Guest190829
05-30-2005, 12:31 AM
Thats the variable you want to use for your template inside a "main" template....so for instance I would have a template called

hack_main


<html>
<body>
<table>
<tr>
<td>$hackbits</td>
</tr>
</table>
</body>
</html>


then you would have another hack for named hack_bits...

hack_bits


<tr>
<td>$row[field1]</td>
<td>$row[field2]</td>
</tr>


You would then use

eval('$hackbits .= "' . fetch_template('hack_bits') . '";');

To make it it show in the hack_main template...

So, when the script is finished the html would be parsed as...

<html>
<body>
<table>
<tr>
<td>

<tr>
<td>$row[field1]</td>
<td>$row[field2]</td>
</tr>

</td>
</tr>
</table>
</body>
</html>



sorry if this is confusing. I am still learning, so I hope im explaining it right..

Oreamnos
05-30-2005, 12:39 AM
ok, that makes sense. i am totally missing the bits part. back to the admincp for me...

thanks
eric

Link14716
05-30-2005, 02:09 AM
It's just a name.

The code used to parse the template
eval('$not_sure_what_this_is .= "' . fetch_template('MY_TEMPLATE') . '";');
does not print anything. It assigns the output to the $not_sure_what_this_is variable for future use. When the final template is called (which uses different code) it parses all the variables in it. Therefore, putting $not_sure_what_this_is in the final template or any template which comes after $not_sure_what_this_is is defined will make it appear where you put the variable.

Oreamnos
05-30-2005, 02:10 AM
cool, thanks!