Forum Moderators: coopster

Message Too Old, No Replies

Dont want to post data if row field is empty

         

outdoorxtreme1

11:03 pm on Jan 25, 2006 (gmt 0)

10+ Year Member



I dont want to post the $row ['thumbnail'] data in this string if the field is empty. Can someone help me out? Thanks.

echo "var marker = createMarker(point, '<div id=\"infowindow\" style=\"white-space: nowrap;\"><b>" . $row ['type'] . "</b><br>" . $row['desc'] . "<br>Latitude&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;" .$row['lat'] . "<br>Longitude&nbsp;" . $row['lon'] . "<br><img src=" . $row ['thumbnail'] . " width=300 height=225><br>Submitted by&nbsp;" . $row['name'] .
"</div>');\n";

Salsa

11:42 pm on Jan 25, 2006 (gmt 0)

10+ Year Member



I think you may be looking for something like this:

echo "var marker = createMarker(point, '<div id=\"infowindow\" style=\"white-space: nowrap;\"><b>" . $row ['type'] . "</b><br>" . $row['desc'] . "<br>Latitude&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;" .$row['lat'] . "<br>Longitude&nbsp;" . $row['lon'];

if ($row ['thumbnail']!= "") { /* ...or whatever condition... */ 
echo "<br><img src=" . $row ['thumbnail'] . " width=300 height=225>"
}

echo "<br>Submitted by&nbsp;" . $row['name'] . 
"</div>');\n";

I hope this helps,
Salsa
_________

outdoorxtreme1

11:59 pm on Jan 25, 2006 (gmt 0)

10+ Year Member



I got a parse error when I tried doind it this way. Did I do something wrong?

outdoorxtreme1

12:03 am on Jan 26, 2006 (gmt 0)

10+ Year Member



I got it to work. Here is the code I used.

echo "var marker = createMarker(point, '<div id=\"infowindow\" style=\"white-space: nowrap;\"><b>" . $row ['type'] . "</b><br>" . $row['desc'] . "<br>Latitude&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;" .$row['lat'] . "<br>Longitude&nbsp;" . $row['lon']; if (!empty($row['thumbnail']))
{echo "<br><img src=" . $row ['thumbnail'] . " width=300 height=225>";}echo "<br>Submitted by&nbsp;" . $row['name'] . "</div>');\n";

Salsa

12:06 am on Jan 26, 2006 (gmt 0)

10+ Year Member



It looks like I left the ";" off the end of

echo "<br><img src=" . $row ['thumbnail'] . " width=300 height=225>"

Just add that on, and maybe there's nothing else.

Salsa
_______

Salsa

12:12 am on Jan 26, 2006 (gmt 0)

10+ Year Member



Good!

A slightly cleaner and more efficient way to do what you are doing would be to build a variable something like this:

$output = "";

$output = "var marker = createMarker(point, '<div id=\"infowindow\" style=\"white-space: nowrap;\"><b>" . $row ['type'] . "</b><br>" . $row['desc'] . "<br>Latitude&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;" .$row['lat'] . "<br>Longitude&nbsp;" . $row['lon'];

if ($row ['thumbnail']!= "") { /* ...or whatever condition... */ 
$output .= "<br><img src=" . $row ['thumbnail'] . " width=300 height=225>";

}

$output .= "<br>Submitted by&nbsp;" . $row['name'] . "</div>');\n";

echo $output

Salsa

12:15 am on Jan 26, 2006 (gmt 0)

10+ Year Member



echo $output;

The ; again! ;-)

outdoorxtreme1

12:39 am on Jan 26, 2006 (gmt 0)

10+ Year Member



I added a url to the thumbnail. I am having problems getting the picture to still show if the slideshow filed is empty. How would I do the code for that?

echo "var marker = createMarker(point, '<div id=\"infowindow\" style=\"white-space: nowrap;\"><b>" . $row ['type'] . "</b><br>" . $row['desc'] . "<br>Latitude:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;" .$row['lat'] . "<br>Longitude:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;" . $row['lon']; if (!empty($row['thumbnail']))
{echo "<br><a href=" .$row ['slideshow'] . " target=_blank><img src=" . $row ['thumbnail'] . " width=300 height=225></a>";}echo "<br>Submitted by:&nbsp;" . $row['name'] . "</div>');\n";