Siggles Posted November 23, 2007 Share Posted November 23, 2007 Some fields in my database do not have any data. One of the fields in the row might or might not contain a URL and the while loop is supposed to make that data a HREF, which works fine but I dont want the 'Click Here' to appear if there is no data in the field of that row. Can I implement an IF statement or something in there to make this work as it still outputs Click Here but just with a link to the same page. Many Thanks <?php include("connection.php"); $result = mysql_query("SELECT * FROM Gigs ORDER BY Date"); while($row = mysql_fetch_array($result)) { echo "<table width=\"100%\" >"; echo "<tr > <td><span class=\"style55\">".date('l jS F Y',strtotime($row['Date']))."</span></td> </tr>"; echo "<tr > <td><span class=\"style55\">".$row['Venue']."</span></td> </tr>"; echo "<tr > <td><span class=\"style55\"><a href=".$row['url']." target=\"blank\">More Info</a></span></td> </tr>"; echo "</table><br>"; } mysql_close($con); ?> Quote Link to comment Share on other sites More sharing options...
Siggles Posted November 23, 2007 Author Share Posted November 23, 2007 I tried but it does the opposite.... if (empty($row['url'])) { echo "<tr > <td><span class=\"style55\"><a href=".$row['url']." target=\"blank\">More Info</a></span></td> </tr>"; } Quote Link to comment Share on other sites More sharing options...
Siggles Posted November 23, 2007 Author Share Posted November 23, 2007 Got it if (!empty Thanks Lol Quote Link to comment Share on other sites More sharing options...
koen Posted November 23, 2007 Share Posted November 23, 2007 then do the opposite :-) if (!empty($row['url'])) Quote Link to comment Share on other sites More sharing options...
Stooney Posted November 23, 2007 Share Posted November 23, 2007 to set a default page in the empty variable: if($row['url']==""){ $row['url']="index.php"; } echo "<tr > <td><span class=\"style55\"><a href=".$row['url']." target=\"blank\">More Info[/url]</span></td> </tr>"; to not show the link altogether if it is empty: (pretty much what you had, only you needed the ! in the if statement. if (!empty($row['url'])) { echo "<tr > <td><span class=\"style55\"><a href=".$row['url']." target=\"blank\">More Info[/url]</span></td> </tr>"; } Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.