1

i use this class for create HTML content

http://code.google.com/p/php-class-html-generator/

I try to build a table in this way , but the html result is wrong...

$messalist = array(...);

    $html = htmltag::createElement('table')->id( $attr['id'] );

        foreach($messagelist as $message){
             $html->addElement('tr')
             ->addElement('td')->setText($message['subject'])
             ->addElement('td')->setText($message['from'])
             ->addElement('td')->setText($message['date'])
             ->addElement('td')->setText($message['size']);
        }

echo $html;

How do it in right way? Thanks

This is generated html:

<table id="messagelist">
    <tr>
    <td>
    <td>
    <td>
    <td>1.91kB</td>23 Feb 11:56 AM</td>To: [email protected]</td>Re: helooo</td></tr>
    <tr>

    <td>
    <td>
    <td>
    <td>1.67kB</td>27 Feb 6:56 AM</td>[email protected]</td>Re: Helloo</td></tr></table>

and this is what i need:

<table id="messagelist">
    <tr>
    <td>1.91kB<td></td>23 Feb 11:56 AM</td><td>To: [email protected]</td><td>Re: helooo</td></tr>
    <tr>
    <td>1.67kB</td><td>27 Feb 6:56 AM</td><td>[email protected]</td><td>Re: Helloo</td></tr></table>
0

2 Answers 2

3

Try:

foreach($messagelist as $message){
     $tr= $html->addElement('tr');
     $tr->addElement('td')->setText($message['subject']);
     $tr->addElement('td')->setText($message['from']);
     $tr->addElement('td')->setText($message['date']);
     $tr->addElement('td')->setText($message['size']);
}
Sign up to request clarification or add additional context in comments.

1 Comment

@Ste So could you post what you expected and what you got? What is wrong?
0

Not too familiar with this generator, but you've only included a semi-colon after the last ->setText. Is that appropriate syntax? I've seen this type of shorthand before, but typically it requires your first to be a full declaration:

$html->addElement('td')->setText($message['subject'])
     ->addElement....
     ->addElement...
     ->addElement....;

Might be worth giving it a try.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.