I know this is a common inquiry, but i just can't seem to get past where i'm stuck w/ this...
Obviously, I am dealing w/ displaying a date field from a MySQL table in my PHP output. because my mind is a bit mushy from being fixated on this problem for so long, i decided to go to the command line rather than continue trial and error by way of modifying my PHP query (which is what i should have done in the first place, i know).
i did some research here, and i see that i can use UNIX_TIMSTAMP() to turn the MySQL date field into something that PHP can use. during my investigation, at the command line, i entered the following:
select unix_timestamp(myTable-date-field) from myTable
which produced the following numerical data for my two rows containing real date data:
1124942400
1118116800
(the other rows' output 0, as there are no valid dates there)
so, i assume my syntax for unix_timestamp() is correct. i looked at http://us3.php.net/date but i'm confused w/ how to write the syntax for the PHP date() function for use w/ this unix_timestap() data. i'm not even sure i should use date()... maybe i should use strtotime(), or mktime? remember i'm a beginner here, so i really am at a loss for this challenge. i've named my date field "showtime" because i'm trying to develop a calendar app for a local musician. here's what i'm trying.
note: this is a separate test script from my larger script. just trying to play w/ this date formatting function.
<?php
$conn = mysql_connect("localhost", "myUser", "myPass");
mysql_select_db("db1", $conn);
$timestp = "SELECT unix_timestamp(showtime) FROM myTable";
$tabledata = mysql_query($timestp, $conn);
while ($tableArray=mysql_fetch_array($tabledata)) {
$format = date(M-d-Y, $tableArray);
echo "$format<br />";
}
?>
i thought this would work, but all i get is a list of zeros representing each row.
what am i doing wrong, and/ or how do i fix this? the rest of my insert query is working properly. i'd like to move on from this so i can start to try the real challenge which is to figure out how i'm going to organize the output into some kind of aesthetically pleasing format.
(if you have any suggestions on how i should approach the format of my larger output, i'd very much appreciate a link to a resource, or even your own advice... i realize i need to concentrate on one challenge at a time of course)
thank you!