Help with retrieve data from mySQL

Hi all,

I have an events table in my database that I’m displaying on a page.

     <?php
//$today = date("w");
$query1 = "SELECT * FROM events";
$result1 = mysql_query($query1);
while($row = mysql_fetch_array($result1)){
		echo "<strong>".$row['title']."</strong><br />".$row['description'];
}
?>

There is also a field in the table for url but not all records have a url.

What I want to do is wrap an href around the description but only if that ID has a url associated with it.

If I do this it adds an href whether it has one or not. (Excuse the syntax if I’m off a little bit.:))

echo "<strong>".$row['title']."</strong><br /><a href='.$row['url'].'>".$row['description']."</a>;

Any one have any ideas? I figure a loop would work but I don’t know how to implement it here.


echo '<strong>', $row['title'], '</strong>';
if ($row['url'] != '') echo '<br /><a href="', $row['url'], '">', $row['description'], '</a>';

:slight_smile:

oh man I can’t believe it was that easy. :slight_smile: thanks!

Ah, I wasn’t aware you wanted that :slight_smile:

in that case:


echo '<strong>', $row['title'], '</strong><br />';
if ($row['url'] != '') echo '<a href="', $row['url'], '">';
echo $row['description']
if ($row['url'] != '') echo '</a>';

or


echo '<strong>', $row['title'], '</strong><br />';
if ($row['url'] != '')
  echo '<a href="', $row['url'], '">', $row['description'], '</a>';
else
  echo $row['description'];

whichever you like best :slight_smile: