Hi, I am using a MYSQL_FETCH_ARRAY and PRINTF satement to pull data and place it into a table. One of the fields is an email field that may or may not have emails. If they do have an email address supplied, I want the table to display a link with the HTML code "HREF=MAILTO:'EMAILADDRESS' , if not, I just want it to display "not entered". Can I nest an "IF" statement inside a "PRINTF" statement. So far, the HTML reads the "IF" statement as characters, and not code. Is there a way to do this or must I try another way by doing a search before the "MYSQL_FETCH_ARRAY"? Thanks in advance. Here is what the code looks like now...
<?php
//List Rows
while ($row = mysql_fetch_array($result, MYSQL_NUM))
{
printf ("
<tr><td width='200'><font color='#FF0000'size='-1'>%s</td>
<td width='200'><font color='#FF0000'size='-1'>%s</td>
<td width='200'><font color='#FF0000'size='-1'>%s</td>
<td width='200'><font color='#FF0000'size='-1'>
[if ($row[3] == 'not entered')
{
echo 'Not Entered';
}
else
{
echo '<a href=mailto:{$row[3]}>Email Me';
}]
</td>
<td width='200'><font color='#FF0000'size='-1'><a href='$row[4]'>My Homepage</td>
<td width='200'><font color='#FF0000'size='-1'>%s</td>
<td width='200'><font color='#FF0000'size='-1'>%s</td><td width='200'><font color='#FF0000'size='-1'>%s</td>
<td width='200'><font color='#FF0000'size='-1'>%s</td><td width='200'><font color='#FF0000'size='-1'>%s</td>
<td width='200'><font color='#FF0000'size='-1'>%s</td>
<td width='200'><font color='#FF0000'size='-1'>%s</td><td width='200'><font color='#FF0000'size='-1'>%s</td>
<td width='200'><font color='#FF0000'size='-1'>%s</td>
<td width='60'><font color='#FF0000'size='-1'>%s</td></tr>",
$row[0], $row[2], $row[1], $row[5], $row[6], $row[7], $row[8], $row[9], $row[10], $row[11], $row[12], $row[13], $row[14]);
}
?>
Timmay!!!
Nesting an "if" statement inside a "printf&qu
Moderator: General Moderators
-
ibanezrg770
- Forum Newbie
- Posts: 4
- Joined: Tue May 20, 2003 9:05 pm
- Wayne Herbert
- Forum Commoner
- Posts: 34
- Joined: Tue Apr 29, 2003 3:13 pm
- Location: Houston, Texas
Why not setup the variable to be printed outside the printf, then just print the contents of the variable in the printf as in
Code: Select all
[if ($row[3] == 'not entered')
{
$printemail = 'Not Entered';
}
else
{
$printemail = '<a href=mailto:{$row[3]}>Email Me';
}