Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

nested if 2

Status
Not open for further replies.

manicleek

Technical User
Jun 16, 2004
143
GB
I am trying to do nested if statements but can't get it to work, basically on the site if a marina is listed it pops up in a box with some of the info, but there are also some fields within this box which may or may not appear. I can get the if statement to work for the box but the one for the intro link is within the echo and so it just prints the code, is there anyway around this, some of the code is below. Also, how do I get the shortentext function to work within the echo too.

Code:
<?php
if($detaillisting == "alisting") {
echo "<table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">
<tr> 
<td><table width=\"495\" border=\"0\" align=\"center\" cellpadding=\"1\" cellspacing=\"0\" bgcolor=\"#6699CC\">
<tr> 
<td><div align=\"center\"> 
<table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"1\">
<tr> 
<td bgcolor=\"#6699CC\"><span class=\"titlelight\">$detailname</span> <spanclass=\"titlelight\">-</span> 
                                                        <span class=\"titlelight\">$detailtown</span></td>
</tr>
<tr> 
<td bgcolor=\"#F2F7F9\"><img src=\"site_images/spacer.gif\" width=\"1\" height=\"1\"></td>
</tr>
<tr> 
<td bgcolor=\"#F2F7F9\"> <p class=\"text\"> 
if ($detailintro <> \"\")
{
                                                          echo ShortenText($detailintro)... <a href=\"details.php?marina=$detailmarina\" class=\"textlink\">more</a> 
}
</p>
 
Make better use of the single and double quotes.
Enclose all static parts in single quotes, then you don't have to escape the souble quotes. Because you are missing a double quote before the second if statement and you can't spot it because this is just to confusing.
Code:
if($detaillisting == "alisting") {
echo '<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td><table width="495" border="0" align="center" cellpadding="1" cellspacing="0" bgcolor="#6699CC">
<tr>
<td><div align="center">
<table width="100%" border="0" cellspacing="0" cellpadding="1">
<tr>
<td bgcolor="#6699CC"><span class="titlelight">'.$detailname.'</span> <spanclass="titlelight">-</span>
                                                        <span class="titlelight">'.$detailtown.'</span></td>
</tr>
<tr>
<td bgcolor="#F2F7F9"><img src="site_images/spacer.gif" width="1" height="1"></td>
</tr>
<tr>
<td bgcolor="#F2F7F9"> <p class="text">';

if ($detailintro != "")
{ ..etc ..

Also:
The if statements have to be in PHP context, not within a quotes HTML output string. That won't work.

You could also use the "here document" syntax with variable interpolation:
Code:
if($detaillisting == "alisting") {
print <<<END
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td><table width="495" border="0" align="center" cellpadding="1" cellspacing="0" bgcolor="#6699CC">
<tr>
<td><div align="center">
<table width="100%" border="0" cellspacing="0" cellpadding="1">
<tr>
<td bgcolor="#6699CC"><span class="titlelight">$detailname</span> <spanclass="titlelight">-</span>
                                                        <span class="titlelight">$detailtown</span></td>
</tr>
<tr>
<td bgcolor="#F2F7F9"><img src="site_images/spacer.gif" width="1" height="1"></td>
</tr>
<tr>
<td bgcolor="#F2F7F9"> <p class="text">
END;
if ( ...etc...
Be aware that here the END; must be on a line itself followed by a semicolon, no extra white space.
 
you cant do????:
Code:
<?php
if($detaillisting == "alisting") {
echo "<table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">
<tr> 
<td><table width=\"495\" border=\"0\" align=\"center\" cellpadding=\"1\" cellspacing=\"0\" bgcolor=\"#6699CC\">
<tr> 
<td><div align=\"center\"> 
<table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"1\">
<tr> 
<td bgcolor=\"#6699CC\"><span class=\"titlelight\">".$detailname."</span> <spanclass=\"titlelight\">-</span> 
                                                        <span class=\"titlelight\">".$detailtown."</span></td>
</tr>
<tr> 
<td bgcolor=\"#F2F7F9\"><img src=\"site_images/spacer.gif\" width=\"1\" height=\"1\"></td>
</tr>
<tr> 
<td bgcolor=\"#F2F7F9\"> <p class=\"text\">";

  if ($detailintro <> \"\"){
      echo ShortenText($detailintro)."... <a href=\"details.php?marina=".$detailmarina."\" class=\"textlink\">more</a>"; 
   }
   echo "</p>";
}
?>

___________________________________
[morse]--... ...--[/morse], Eric.
 
Use of single quotes to delineate static strings, in particular around static strings that contain double quotes, enhances readability -- you don't have to escape all those interior double-quotes.

And readability enhances maintainability.



Want the best answers? Ask the best questions!

TANSTAAFL!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top