PHP Pear ITX add and replace block file

806

I use PEAR ITX to add template. What my problem is, first 2 time ($number>2) condition match and the $fileName2 is added success, block show as expect; but when the third time ($number==2) condition match but $fileName1 seem like fail to load, it doesn't show any thing. Here is my sample code:

$template = new HTML_Template_ITX("./templates");
$template->loadTemplatefile($maintemplate,true,true);

while($row = mysql_fetch_array($result))
{
    if($number==2)
    {
        $template->addBlockFile("CANDIDATES","CAN",$fileName1);|
        $template->setCurrentBlock("CAN");
        //do anything i need
    }else if($number>2) //first 2 times condition match, everything works well
    {
        $template->addBlockFile("CANDIDATES","CAN",$fileName2);
        $template->setCurrentBlock("CAN");
        //do anything i need
    }

    $template->setCurrentBlock("MAIN");
$template->parseCurrentBlock();
}

The situation can be contrary, if first 2 times condition match ($number==2), then the third time condition match ($number>2) but the problem still the exist.

What i found is the replaceBlockfile(), i tried but doesn't work. Anyone can tell me what wrong is it? Thank you.

467

Answer

Solution:

Seem like no one can answer my question, but i had figure out the problem. In my question, every times loop is using the same $template, because of $template outside the loop. What I need to do is put the:

$template = new HTML_Template_ITX("./templates");
$template->loadTemplatefile($maintemplate,true,true);

inside the while loop, it is mean every time it loop will create a "NEW" table.

People are also looking for solutions to the problem: Passing Parameters in PHP

Source

Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.