Jump to content

Archived

This topic is now archived and is closed to further replies.

Mortier

TemplatePower -> using my select manipulation

Recommended Posts

Hello people!

I have just started using TemplatePower as a templating engine for my website. But I have come to the following problem: how do I apply my selectmanipulation() function?
[code]
<?
// als $data_type == 1, moet het resultaat met een while worden opgehaald
// als $data_type == 0, gebruiken we de data als array
// $data_name == veldnaam
// $data == array of sql query
// $set is array met veldwaarden
// $css is stylenaam
function ManipulateSelect($data_type, $data_name, $data, $set, $css)
{
echo '<select name="' . $data_name . '" class="' . $css .'">';
if($data_type == 1) //while
{
//$data == mysql query
$result = mysql_query($data);
while($list_data = mysql_fetch_assoc($result))
{
echo $list_data['id'];
if($list_data['id'] == $set[$data_name])
{
$selected[$data_name] = 'selected';
}
else
{
$selected[$data_name] = '';
}
echo '<option value="' . $list_data['id'] . '" ' . $selected[$data_name] . '>' . htmlspecialchars($list_data['name']) . '</option>';
}
}
else //array met foreach
{
foreach($data as $id => $value)
{
if($id == $set[$data_name])
{
$selected[$data_name] = 'selected';
}
else
{
$selected[$data_name] = '';
}
echo '<option value="' . $id . '" ' . $selected[$data_name] . '>' . $value . '</option>';
}
}
echo '</select>';
}
?>
[/code]

That's my function. It works perfect without templates ( it makes the option selected which is selected according to POST or SQL.

Any ways of making it compitable with my TemplatePower??

Thanks for your help in advance,

Alex

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.