Jump to content

[SOLVED] When a field doesn't exist.


Siggles

Recommended Posts

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);

?>

Link to comment
Share on other sites

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>";
         }

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.