ccmanz ccmanz - 4 months ago 20
PHP Question

How to place foreach loop inside a <td> tag

How do you place a foreach loop inside a tag?

here's the code:

foreach( $designer_posts as $designer_post ) {
$tags = get_the_tags($designer_post->ID);
$imageThumb = get_the_post_thumbnail( $designer_post->ID, "thumbnail" );

$html .= '<tr>';
$html .= '<th scope="row">View</th>';
$html .= '<td><p>'.$designer_post->post_title.'</p></td>';
$html .= '<td>'FOREACH LOOP HERE!!!'</td>';
$html .= '<td>'.$imageThumb.'</td>';
$html .= '</tr>';
}


I keep getting an error. Could you help me with the PROPER syntax?

Answer
foreach( $designer_posts as $designer_post ) {
        $tags = get_the_tags($designer_post->ID);
        $imageThumb = get_the_post_thumbnail( $designer_post->ID, "thumbnail" );

        $html .= '<tr>';
        $html .= '<th scope="row">View</th>';
        $html .= '<td><p>'.$designer_post->post_title.'</p></td>';   
        $html .= '<td>';
            foreach() {
                $html .= 'The rest of the HTML code';
            }
        $html .= '</td>';                     
        $html .= '<td>'.$imageThumb.'</td>';                  
        $html .= '</tr>';                    
}