1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

HELP! - Dynamically filling PHP Tabe with FORMATTED Date & Time

Discussion in 'PHP' started by romsky, Aug 6, 2005.

  1. #1
    Here is the code that I am using:
    -------------------------


    //Connect to database

    mysql_connect ( $dbhost, $dbuser, $dbpass)or die("Could not connect: ".mysql_error());
    mysql_select_db($dbname) or die(mysql_error());



    $tr_num = $_REQUEST['tr_num'];


    $result = mysql_query("select * from pack_stat WHERE tr_num=$tr_num order by updated");


    echo "
    <html>
    <body>
    <center>
    <table BORDER='1' CELLSPACING='1' CELLPADDING='0' WIDTH='585' bordercolordark='#333333' bordercolorlight='#666666'>
    <thead>
    <td WIDTH='70'>Tracking#</td>
    <td WIDTH='50'>User</td>
    <td WIDTH='170'>Status</td>
    <td WIDTH='95'>Date</td>
    <td WIDTH='50'>Time</td>
    <td WIDTH='150'>Last Updated</td>
    </thead>
    ";


    while($r=mysql_fetch_array($result)){


    $tr_num=$r["tr_num"];
    $user=$r["user"];
    $status=$r["status"];
    $date=$r["date"];
    $time=$r["time"];
    $updated=$r["updated"];


    echo "
    <tr>
    ".$tr_num=$r["tr_num"]."</td>
    <td>".$user=$r["user"]."</td>
    <td>".$tstatus=$r["status"]."</td>

    <td>".date("m/d/Y",$date=$r["date"])."</td>
    <td>".date("H:i",$time=$r["time"])."</td>

    <td>".$updated=$r["updated"]."</td>
    </tr>
    ";

    }


    ?>

    -------------------------

    Now every time the page loads ALL dates are 12/31/1969, and the time is always 16:00.

    The data exists in the tabe as follows:

    Date: "2005-08-06"
    Time: "17:04:00"

    I want it to look like
    08/06/2005

    17:04

    I have been able to format the data but it won't dynamically fill the table.

    Please HELP!
     
    romsky, Aug 6, 2005 IP
  2. dpak

    dpak Peon

    Messages:
    111
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    It's because the date function takes a timestamp, and mysql returns it as a string. You could use the strtotime and the date functions to format them, or you could format the date and time in the mysql query.

    In php it would be something like this...

    I haven't tested that, so I'm not positive it will work, but try it out.
     
    dpak, Aug 6, 2005 IP
  3. romsky

    romsky Peon

    Messages:
    2
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    You are a frickin' genious!

    It works great, thanks!
     
    romsky, Aug 6, 2005 IP