Just a quick question. I want to post what is in the database but if the field is empty then i want it to say "No Date" else post the date in the table. At the moment my code only shows the "No Date" even when I know there is a date it should be showing. Here is my code

while($row = mysql_fetch_array($result))
if(empty($_REQUEST['dtFirstContactSt'])) {
echo "<td>" . "No Date </td>";
} else {
echo "<td>" .$row['dtFirstContactSt']. "</td>";
}

On line two you are referencing the $_REQUEST superglobal instead of the $row variable.

Hmm.. so I would make the code? I tried it but still got the 0000-00-00 that the database defaults into the database if no date was entered.

while($row = mysql_fetch_array($result))
if(empty($row['dtFirstContactSt'])) {
echo "<td>" . "No Date </td>";
} else {
echo "<td>" .$row['dtFirstContactSt']. "</td>";
}

Can you show your table structure as well as your sql query?

<?
include "include/session.php";

include "include/z_db.php";
?>
<?

require "bottom.php";
?>
<!doctype html public "-//w3c//dtd html 3.2//en">

<html>

</head>

<!-- <body bgcolor="#339999"> -->
<body bgcolor="white">
<!--  <form action="index.php" method="post">
<br /><input type="submit" value="HOME" ;/></form><br />  -->

<img src="logo.jpg" width="197" height="193" align="right"><br /><br /><br /><br /><br />
<br /><br /><br /><br /><br />
<FORM>
<INPUT TYPE="BUTTON" VALUE="New Tour" ONCLICK="window.location.href='site'">
</FORM>
<?php
$result = mysql_query("SELECT * FROM Project1");

echo "<table border='1'>

<tr>
<th>School</th>
<th>Teacher</th>
<th>First Contact start date</th>
<th>Development Start</th>
<th>Development End</th>
<th>Pricing Start</th>
<th>Pricing End</th>
<th>Marketing Start date</th>
<th>Price Based On</th>
<th>Trip Assigned To</th>
<th>Trip Made</th>
<th>Notes</th>
</tr>";

while($row = mysql_fetch_array($result))
{ 
echo "<tr>";

echo "<td>" .$row['School'] . "</td>";
echo "<td>" .$row['Teacher'] . "</td>";
if(empty($row['dtFirstContactSt'])) {
echo "<td>" . "No Date </td>";
} else {
echo "<td>" .$row['dtFirstContactSt']. "</td>";
}
echo "<td>" .$row['dtDevelopmentSt']. "</td>";
echo "<td>" .$row['dtDevelopmentEnd']. "</td>";
echo "<td>" .$row['dtPricingSt']. "</td>";
echo "<td>" .$row['dtPricingEnd']. "</td>";
echo "<td>" .$row['dtMarketingSt']. "</td>";
echo "<td>" .$row['PriceBasedOn']. "</td>";
echo "<td>" .$row['TripAssignedTo']. "</td>";
?>
<td><input type="checkbox" name="TripMade" value= "<?php $row['TripMade'] ?>" > </td>
<td><textarea name="Notes" rows="1" cols="10"><?php echo $row["Notes"]?></textarea> </td>
<?php
//echo "<td>" .$row['Notes']. "</td>";
echo "<td>" . "<a href=Edit_Form.php?UniqueIdentifier=$row[UniqueIdentifier]> Edit </a></td>";

echo "</tr>";
}

echo "</table>";
mysql_close($con);
?>

<br />

<meta name="GENERATOR" content="Arachnophilia 4.0">
<meta name="FORMATTER" content="Arachnophilia 4.0">
</head>

<body bgcolor="#ffffff" text="#000000" link="#0000ff" vlink="#800080" alink="#ff0000">
<center>
 

</body>

</html>

Let me know if you need anything else

Sorry, I don't see where the problem is, unless there's data missing in the table. If you have command line access to MySQL or if you have phpMyAdmin, you should run a query to check the table contents directly and make sure there is a value for the dtFirstContactSt field in the table.

Well if no date is entered into the database then the database defaults a "0000-00-00" into the field. do you think it could be the database using 0000-00-00 as a default that is throwing off the if else statement?

Well yes that will keep the if statement from ever printing No Date. Instead you may want to run

if(!strcmp($row['dtFirstContactSt'], '0000-00-00')) { 
   //...
} else {
   //...
}

This will make sure that if $row['dtFirstContactSt'] contains 0000-00-00, it will print whatever is in the first set of braces.
So is the table now printing the appropriate dates when there is information in the field?

Awesome. Works perfect now. Thanks so much.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.