Re: HTML Table display based upon field contents
| From: | Tularis | Date: | Sat, 24 Jul 2004 21:23:49 +0000 |
| Subject: | Re: HTML Table display based upon field contents | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-191778@lists.php.net to get a copy of this message | ||
Robb Kerr wrote:
I have a complicated table that needs to be altered depending upon the contents of a field in one of my recordsets. I've tried several approaches and need to know what you recommend. I've created three totally different tables and put the HTML code for each into a database. Then I used PHP to insert the relevant code into the page depending upon the contents of a field in a different database. Result - the appropriate code is inserted properly into the HTML. Problem - the HTML table I'm trying to insert contains PHP code which is not executed after being inserted. Because sometimes the HTML table needs 4 rows and other times only 2, I tried enclosing the appropriate <tr>s in a PHP IF statement (see below). Problem - PHP IF wasn't executed, both <tr>s embedded appeared on page anyway. And, sometimes, the relevant <tr>s will include PHP code so this embedding technique won't work. <?php if ($row_RS_PageContent['PageType'] != "2") { ?> <tr><td width="200" height="0" bgcolor="99CCCC"> </td> <td width="20" height="0"> </td> <td height="0" align="left" valign="top"> </td> <td height="0" align="right" valign="top"> </td> <td width="20" height="0"> </td> <td width="5" height="0" bgcolor="333366"> </td></tr> <tr><td width="200" height="0" bgcolor="99CCCC"> </td> <td width="20" height="0"> </td> <td height="0" align="left" valign="top"> </td> <td height="0" align="right" valign="top"> </td> <td width="20" height="0"> </td> <td width="5" height="0" bgcolor="333366"> </td></tr> <?php } ?> Should I simply describe the entire relevant <tr>s on one line, appropriately escape them, assign the to a variable and then use an ECHO to put them on the page? Or does someone have a simpler more elegant solution? Thanx just use eval() on that string, it's not elegant, nor is it really secure, but it'll work fine.