-
How to change month display?
Hi
Need help to change the month display from the current.
Current display: Show date 1/8, 3/8, 22/8, 3/9, 7/9, 16/9, 5/10, 14/10 ...
Need to change the format to be:
New Display: Show date Aug 1, 3, 22
Sept 3, 7, 16
Oct 5, 14 ....
Any helpful sample is greatly appreciated.
Code:
<span class="content"><b>Show dates:
<?
$query1 = "select DAYOFMONTH(ShowDate) as showday, MONTH(ShowDate) as showmon from Schedule where Timetable = '".$arr["Name"]."' and EndDate = '00000000' and ShowDate >= '".date("Ymd")."') order by ShowDate";
$result1 = mysql_query($query1,$dbConnect);
$comma=0;
while ($rs=mysql_fetch_array($result1)){
print " ".$rs["showday"]."/".$rs["showmon"];
$comma = $comma+1;
if($comma<mysql_num_rows($result1)) echo", ";
else echo".";
}
mysql_free_result($result1);
?>
-
print " ".$rs["showday"]."/".$rs["showmon"];
becomes...
Code:
print " ";
if ($lastmonth != $rs["showmon"]) {
if ($rs["showmon"] == 1){echo "Jan";}if ($rs["showmon"] == 2){echo "Feb";}
if ($rs["showmon"] == 3){echo "Mar";}if ($rs["showmon"] == 4){echo "Apr";}
if ($rs["showmon"] == 5){echo "May";}if ($rs["showmon"] == 6){echo "Jun";}
if ($rs["showmon"] == 7){echo "Jul";}if ($rs["showmon"] == 8){echo "Aug";}
if ($rs["showmon"] == 9){echo "Sep";}if ($rs["showmon"] == 10){echo "Oct";}
if ($rs["showmon"] == 11){echo "Nov";}if ($rs["showmon"] == 12){echo "Dec";}
} else { print ","; }
print " ".$rs["showday"];
$lastmonth = $rs["showmon"]
oo. but then you want it to check that only shows if it changes... blah. added edits... and set $lastmonth = -1 somewhere earlier.
Last edited by sharth; 08-20-2005 at 02:43 PM.
Reason: adding [code] tags.
irc.freenode.net #justlinux The Not So Official JL IRC Channel.
¤ Debian ¤ Apt-Get ¤
-
Thanks Sharth.
I will try it and see if it works.
-
Hi Sharth
It works! Thanks! Btw, I am trying to make a carriage-return for every different month but unfortunately did not work. Any idea?
Currently display is: Jan 1, 2, 3, 4 Feb 3,7,9,11,20 Mar 9,13,14,16
Trying to make the display as:
Jan 1, 2, 3, 4
Feb 3, 7, 9, 11, 20
Mar 9, 13, 14, 16
Is it possible? Thanks!
-
if ($lastmonth != $rs["showmon"]) {
add to the end of that line (or on the beginning of the next line, like make room in between the two).
echo "\n<br>";
irc.freenode.net #justlinux The Not So Official JL IRC Channel.
¤ Debian ¤ Apt-Get ¤
-
Hi Sharth
Thanks! Works great!
-
Can't you get the month names out of MySQL?
Sure you can; look here:
http://dev.mysql.com/doc/mysql/en/da...functions.html
(at the DATE_FORMAT function), change your select to:
select DAYOFMONTH(ShowDate) as showday, DATE_FORMAT(ShowDate, "%M") as showmon <...>
, and then showmon will be the string name of the month. No need for a lookup table and PHP to use it, when the database will do it for you.
Also, doesn't PHP have a date/time type that the MySQL library will map to? I know Python's database API returns MySQL datetime fields as a special "MySQLclient.datetime" instance; this can be converted to a standard Python date fairly easily, at which point the language libraries can extract the day-of-month and month-name. That'd be another option if you were using Python; I don't know if PHP's database interface works like that or not.
-
Hi bwkaz
Thanks! Anyway, I followed Sharth's example and it is working fine. I am grateful to both of you for being so helpful.
-
yeah, i knew that mysql had something nice and simple for the months, but I wasn't sure if (s)he was even using mysql. So whatever. It's really kinda gross code too..
I wasn't able to find anything in normal php to do it fairly easily, so i just figured go with that. It's all good either way though.
:edit: also, (s)he was using the shorter form, no clue if that's easy/hard to do.
Last edited by sharth; 08-23-2005 at 02:32 PM.
irc.freenode.net #justlinux The Not So Official JL IRC Channel.
¤ Debian ¤ Apt-Get ¤
-
Thanks Sharth. I am using PHP with MySQL and being a beginner, I am rather blur when come with resolving such problem. I am searching for good database example lessons where I can further improve myself. Nice to meet wonderful people here to help when in need. Thanks all ...
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
|