Jump to content


Photo

Date Formatting within a While Loop array readout...


  • Please log in to reply
2 replies to this topic

#1 mikerosenthal

mikerosenthal
  • New Members
  • Pip
  • Newbie
  • 4 posts

Posted 15 September 2006 - 04:31 AM

im sure the subject of this post gives me away as a total newbee...
i have been trying all night to solve this seemingly simple problem.
Basically i am needing to format data being read out of a mysql database with php. It is an event listing script, where it reads through a table, pulls out each event, and displays the date, time, name of the event. i need to have the date formatted in a certain way (ideally Day of Week, Date#, Month, but whatever...) which seems really straightforward.
here is my script:
<?
$q = "SELECT * FROM webcal_entry ORDER by cal_date";
    $r = mysql_query($q);
while ($a = mysql_fetch_array($r)) {
print ("$a[date_test] $a[cal_name] $a[cal_time]pm");
}
?>
basically i dont know how to apply this:
SELECT date_format(date_test, '%a %D %b %Y') as formatted_date from webcal_entry
to each entry in the array.
hm. im not sure im asking this question in a clear way. does this make any sense?
im able to get it to do what i need when my script is just this:
<?php

$q = "SELECT date_format(date_test, '%a %D %b %Y') as formatted_date from webcal_entry;";
    $r = mysql_query($q);
while ($a = mysql_fetch_array($r)) {
print ("$a[formatted_date]");
}
?>
but i need it happening as its looping through all the events in my table.

surely this is easy...can anyone help?

-mike


#2 btherl

btherl
  • Staff Alumni
  • Advanced Member
  • 3,893 posts
  • LocationAustralia

Posted 15 September 2006 - 04:40 AM

You can do

SELECT date_format(date_test, '%a %D %b %Y') as formatted_date, cal_name, cal_time from webcal_entry

It's good coding practice to specify which columns you want in a SELECT too.

#3 mikerosenthal

mikerosenthal
  • New Members
  • Pip
  • Newbie
  • 4 posts

Posted 15 September 2006 - 05:03 AM

nice. thanks. knew it had to be simple.
and thanks for the tip about columns too!
just getting started...





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users