PHP link from DB

June 16, 2010 at 03:06:43
Specs: Windows

i'm trying to conditionally display a link stored in a field in my.

I can display the link in html, and I can use php to check if the field is null or
not....just having trouble with the syntax for combining them in PHP, which I don't
really know at all.

in HTML the following works:

<a target="_blank" href="<?php echo $results[$i]['courier_tracking'] ; ?>" class="txtLink" > Track </a>

this shows a link "Track" but the link shows irrespective of whether there is
information in the DB or not.

I managed to get the following code which works fine. This displays the word "Track" only if the field in the DB isn't Null. So this is sort of what I want, except that I now need to turn the middlle line into a hyperlink, and I can't figure out the
PHP syntax.

if ($results[$i]['courier_tracking'] != NULL) {
	echo 'Track';

So far I've got something like this.....

echo '<a href="$results[$i]['courier_tracking'];">Track</a>';

......but it doesn't work and I can't for the life of me figure out what's wrong in here.

Any shining light would be much appreciated.

See More: PHP link from DB

Report •

June 17, 2010 at 07:26:46
if ($results[$i]['courier_tracking'] != NULL) {
	echo "<a href='" . $results[$i]['courier_tracking'] . "'>Track</a>";

or perhaps

<a target="_blank" href="<?php echo (!is_null($results[$i]['courier_tracking']) ?
 $results[$i]['courier_tracking'] : '') ; ?>" 
class="txtLink" > Track </a>

The latter would show up as a link to the page if $results[$i]['courier_tracking'] were null.


Report •
Related Solutions

Ask Question