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
https://forums.phpfreaks.com/topic/78609-solved-when-a-field-doesnt-exist/
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>";
         }

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.