
September 13th, 1999, 04:46 PM
|
|
Guest
|
|
Posts: n/a
Time spent in forums:
Reputation Power:
|
|
|
Using a mySQL field as timestamp -- this is my PHP code to query the timestamp using mySQL "UNIX_TIMESTAMP" -- is there a better way than doing two different selects here? This code works fine, but I'd like it to be as effecient as possible:
$result = mysql_query("SELECT * FROM questions where (quest_id=$quest_id)",$db); ## $quest_id is primary key - its the question we're grabbing
$second = mysql_query ("SELECT UNIX_TIMESTAMP(quest_date) as $date from questions where (quest_id=$quest_id)",$db);
## Above, I've already queried this table, and the timestamp value would be in $myrow["quest_date"] per below, but above I query again to get in the UNIX_TIMESTAMP form. This works, but why must I query twice? Is there a way to grab "quest_date" in the first query as UNIX_TIMESTAMP (therefore making second query above no longer needed??)
## the rest of the code goes on to do this:
if ($myrow = mysql_fetch_array($result)) {
## ... blah blah blah, then prints date like this:
echo date ("F j, Y", mktime ($date));
Like I said - this works fine, but seems awfully messy.
Help and comments appreciated.
I am using timestamp because I need the date to be automatically entered when the row is updated.
|