Forum Moderators: coopster

Message Too Old, No Replies

HTML in php

using html in php

         

Steerpike

11:19 pm on Aug 22, 2006 (gmt 0)

10+ Year Member




Just the other day I saw a post titled '100 ways to know you're writing spagetti code' and, after wriggling uncomfortably in my chair while reading it, I saw one of the ways was 'You have html in your php.'

Every other one I read I could see made sense and was a great help but I can't figure out how you would loop through a recordset from a database and stick it into an html table without using html within the php code.

Can anyone post an example of the right way to do this?

Cheers.

jatar_k

11:50 pm on Aug 22, 2006 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



that particular one is up for debate, I don't see it as being an issue unless you are print'ing or echo'ing large blocks of html that don't actually need to be processed.

echo '<table>';
echo '<tr><td>this is a waste</td></tr>';
echo '</table>';

this is obviously a very small example. I see lots of code that has massive amounts of html printed out via php.

this would be simpler and makes more sense

?>
<table>
<tr><td>this isn't a waste</td></tr>
</table>
<?

escaping from the parser to output tons of html. I skip in and out for doing single vars or small opperations. If I need to create a table using a loop then I may have php echo'ing chunks of unprocessed html.

and don't worry Steerpike, we all squirm when we read that thread ;)

[edited by: jatar_k at 11:54 pm (utc) on Aug. 22, 2006]

jatar_k

11:54 pm on Aug 22, 2006 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



for those who may not know what we are talking about, it is a library [webmasterworld.com] thread

Top 100 Signs That I Am Writing Spaghetti Code in PHP [webmasterworld.com]

it is a great thread