View Full Version : Only post code if MySQL row data exists?

10-07-2012, 03:19 AM
I have this code on my website that grabs the "official" MySQL database row data and spits it out as a clickable link.

The problem is that if the "official" MySQL row is empty, the code spits out the current website page URL.

Is there a way to edit the below code so that it only spits out the below code if there is data in the mysql "official" row?

I'm guessing some sort of IF statement?

<div class="movietitles"><img src="/images/35genre.png" />Official Site: <a href="{$official}">link</a></div>

Cloud Ghost
10-07-2012, 04:00 AM
$num = mysql_num_rows($myquery);
if($num > 0) {
// More than one row was returned.

Replace $myquery with the variable assigned to mysql_query().

10-07-2012, 04:06 AM
Do I add that code further up the php code?

Cloud Ghost
10-07-2012, 04:41 AM
Add that code right after making the query to the database with mysql_query().