On Sat, 28 Apr 2001, Andras Kende wrote:
> Hello,
>
> I pull some data from mysql with the php code below.
> On the date field if there is no date on mysql it displays : 0000-00-00
> 00:00:00
>
> I would like to change this 0000-00-00 00:00:00 to "no date" for example..
hmm... mysql can do this, works like this:
IF(EXPR,TRUE,FALSE):
mysql> select IF(UNIX_TIMESTAMP(lastmod)<=0,"NoDate",lastmod) as date from
links;
+---------------------+
| date |
+---------------------+
| 2001-04-22 08:04:07 |
| 2001-04-22 08:04:10 |
| 2001-04-22 08:03:45 |
| 2001-04-22 08:03:42 |
| 2001-04-22 08:03:41 |
...
| 2001-04-22 08:03:45 |
| 2001-04-22 08:04:05 |
| 2001-04-22 08:03:43 |
| NoDate | (normally 0000-00-00 00:00:00)
| 2001-04-22 08:04:06 |
| 2001-04-22 08:03:56 |
| 2001-04-22 08:04:08 |
| 2001-04-22 12:57:27 |
| 2001-04-27 21:26:36 |
| 2001-05-07 22:35:45 |
+---------------------+
28 rows in set (0.00 sec)
> Or if the cel is empty to " " (because otherwise the tableborders are messed
> up)
If by empty you mean NULL, you could probably do similar as above:
mysql> select IF(lastchk IS NULL," ",lastchk) from links;
+--------------------------------------+
| IF(lastchk IS NULL," ",lastchk) |
+--------------------------------------+
| 24 |
| 9 |
| |
| 8 |
...
| |
| 6 |
| 1 |
| |
| |
| |
| |
+--------------------------------------+
28 rows in set (0.01 sec)
... the will hold the table cell in html.
>
> I tried to put an if statement inside the while {} but i cannot figured
> out...
yep you could do this too. I don't know which is faster as i have not been
able to test either under high enough load to make a difference :( i
prefer to let mysql do all the work it can because i figure the web server
is busy enough will all kind of regular html requests.
good luck... hope this helped.
Bill
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]