On Sat, 24 Jul 2004 17:47:48 -0400, Kevin wrote: > Hi Robb, > > I am a newbie so I wanted to ask a stupid question. In your code below if > the first if statement is true it ends the php processing and then you > reopen with a new <?php before the closing }. What would happen if you took > out the ?> before the first <tr> tag and the </php before the }. Would that > work? > > Sorry if this is just dumb. Trying to learn. :) > > Kevin > > -----Original Message----- > From: Robb Kerr [mailto:[EMAIL PROTECTED] > Sent: Saturday, July 24, 2004 4:47 PM > To: [EMAIL PROTECTED] > Subject: [PHP] HTML Table display based upon field contents > > 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 > -- > Robb Kerr > Digital IGUANA > Helping Digital Artists Achieve their Dreams > ---------------------------------------------------- > http://www.digitaliguana.com > http://www.cancerreallysucks.org
To do what you're suggesting, you'd have to put each line of HTML in separate ECHO statements (see below). The problem with this approach is that the table will eventually contain very complex code in each cell. I'd have to do extensive escaping to make sure the code is correctly interpreted. I used a shortcut syntax that allows you to embed several lines of HTML in an IF statement without having to escape everything. The short PHP statement after the embedded lines tells PHP that the embedded code is embedded as if it was ECHOed line by line. This works most of the time. Just not in this instance. To use your suggestion, the code would have to look like this... <?php if ($row_RS_PageContent['PageType'] != "2") { echo '<tr>'; echo '<td width=\"200\" height=\"0\" bgcolor=\"99CCCC\"> </td>'; echo '<td width=\"20\" height=\"0\"> </td>'; echo '<td height=\"0\" align=\"left\" valign=\"top\"> </td>'; etc. } ?> Note all of the escaping required to simply define the table. You'd have tons more to do when images, links, JavaScript calls, etc. are placed in the table. -- Robb Kerr Digital IGUANA Helping Digital Artists Achieve their Dreams ---------------------------------------------------- http://www.digitaliguana.com http://www.cancerreallysucks.org -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php