User not logged in - login - register
Home Calendar Books School Tool Photo Gallery Message Boards Users Statistics Advertise Site Info
go to bottom | |
 Message Boards » » PHP date help Page [1]  
YOMAMA
Suspended
6218 Posts
user info
edit post

I have a column in a database that has a time stamp.

I am querying these columns to dump out on a sheet.

I'm able to display the dates for the cells that contain an actual timestamp but there are cells that only have "0" in them. So for these cells there is a defualt date of "12-31-1969". All I want is a big fat "0" Please help.

the code I have:


while (
$row = mysql_fetch_array($sql)) {
$username = $row["username"];
$lastvisit = date("n-d-Y",$row["lastvisit"]);
$lastactivity = date("n-d-Y",$row["lastactivity"]);
$lastpost = date("n-d-Y",$row["lastpost"]);

2/21/2006 5:38:13 PM

YOMAMA
Suspended
6218 Posts
user info
edit post

I know I could write a "if" statement but I was just wondering if there is an easier way to do this.

2/21/2006 5:41:40 PM

HaLo
All American
14263 Posts
user info
edit post

i doubt it.

an if statement would add 3-5 lines. just use the if

2/21/2006 6:05:21 PM

wolftrap
All American
1260 Posts
user info
edit post

rule #324: always make mysql do the work if possible

2/21/2006 6:07:27 PM

qntmfred
retired
40726 Posts
user info
edit post

use the ternary operator. it gives the functionality of an if/else statement, but in 1 compact line

$lastvisit = ($row["lastvist"] == 0 ? 0 : date("n-d-Y",$row["lastvisit"]));

2/21/2006 6:08:05 PM

Maugan
All American
18178 Posts
user info
edit post

DECODE

2/21/2006 6:16:18 PM

YOMAMA
Suspended
6218 Posts
user info
edit post

DECODE You

2/21/2006 6:27:22 PM

YOMAMA
Suspended
6218 Posts
user info
edit post

^^^ hmm didnt work but I will read about that to see if its just somethign simple to edit

[Edited on February 21, 2006 at 6:29 PM. Reason : ef]

2/21/2006 6:29:28 PM

YOMAMA
Suspended
6218 Posts
user info
edit post

ok got it:

$lastvisit = ($row["lastvisit"] == 0) ? "No Date" : date("n-d-Y",$row["lastvisit"]);


Thanks !

2/21/2006 6:38:46 PM

 Message Boards » Tech Talk » PHP date help Page [1]  
go to top | |
Admin Options : move topic | lock topic

© 2024 by The Wolf Web - All Rights Reserved.
The material located at this site is not endorsed, sponsored or provided by or on behalf of North Carolina State University.
Powered by CrazyWeb v2.39 - our disclaimer.