0

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

Edited by JOUATT: n/a

2
Contributors
9
Replies
10
Views
7 Years
Discussion Span
Last Post by EvolutionFallen
0

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

Edited by JOUATT: n/a

0
<?
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

0

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.

0

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?

1

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?

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.