|
|
|
|
||||||
![]() |
|
|
LinkBack | Outils de la discussion |
|
|
#1 |
|
Messages: n/a
Hébergeur: |
Hello, I am a novice (very novice) webmaster, and am trying to retrieve the most recent record from a database to display on a homepage. It all works well enough with one exception, which I am sure is just my overlooking something - I cannot change the date format. When I change the field "DTE" to a date_format in the query as below, my date results are blank. Looking at the code below, can someone please suggest what I might be doing incorrectly? Any is greatly appreciated - **** mysql_connect("localhost", "username", "password") or die(mysql_error()); mysql_select_db("stjojone_primary") or die(mysql_error()); $data = mysql_query("SELECT LTRGCL_DTE,date_format(DTE,'%W,%M,%D,%Y'),BLTN_FIL E FROM bulletin_store ORDER BY DTE DESC LIMIT 0,1") or die(mysql_error()); Print "<div align=center><table class=\"SJTableInfo\">"; Print "<tr><td align=center><h5>Date</h5></td><td align=center><h5>Liturgical Date</h5></td></tr>"; while($info = mysql_fetch_array( $data )) { Print "<tr>"; Print "<td class=\"SJTdInfo\" align=\"center\">".$info['DTE'] . "</td><td class=\"SJTdInfo\" align=\"left\"><a href=/bulletin_files/".$info['BLTN_FILE'] ." title=\"Click to view or download the file\" target=\"_blank\">".$info['LTRGCL_DTE'] .."</a></td>"; } Print "</table></div></br></br>"; **** |
|
|
|
#2 |
|
Messages: n/a
Hébergeur: |
On Fri, 04 Jan 2008 20:24:53 -0600, seastl <<nospam@nospam.com>>
wrote: > >Hello, > >I am a novice (very novice) webmaster, and am trying to retrieve the >most recent record from a database to display on a homepage. It all >works well enough with one exception, which I am sure is just my >overlooking something - I cannot change the date format. When I change >the field "DTE" to a date_format in the query as below, my date >results are blank. Looking at the code below, can someone please >suggest what I might be doing incorrectly? Any is greatly >appreciated - > >**** >mysql_connect("localhost", "username", "password") or >die(mysql_error()); >mysql_select_db("stjojone_primary") or die(mysql_error()); >$data = mysql_query("SELECT >LTRGCL_DTE,date_format(DTE,'%W,%M,%D,%Y'),BLTN_FI LE FROM >bulletin_store ORDER BY DTE DESC LIMIT 0,1") or die(mysql_error()); >Print "<div align=center><table class=\"SJTableInfo\">"; >Print "<tr><td align=center><h5>Date</h5></td><td >align=center><h5>Liturgical Date</h5></td></tr>"; >while($info = mysql_fetch_array( $data )) >{ >Print "<tr>"; >Print "<td class=\"SJTdInfo\" align=\"center\">".$info['DTE'] . >"</td><td class=\"SJTdInfo\" align=\"left\"><a >href=/bulletin_files/".$info['BLTN_FILE'] ." title=\"Click to view or >download the file\" target=\"_blank\">".$info['LTRGCL_DTE'] >."</a></td>"; >} >Print "</table></div></br></br>"; >**** Ok, I changed to "date_format(DTE,'%W,%M %D,%Y') as 'DTE',", and seems to work perfectly now. Then I find that it sorts on the literal date, not the actual date value now! Is there an easy enough fix for that, or should one just sort on the ID autonumber column? |
|
|
|
#3 |
|
Messages: n/a
Hébergeur: |
seastl < wrote:
> On Fri, 04 Jan 2008 20:24:53 -0600, seastl <<nospam@nospam.com>> > wrote: > >> Hello, >> >> I am a novice (very novice) webmaster, and am trying to retrieve the >> most recent record from a database to display on a homepage. It all >> works well enough with one exception, which I am sure is just my >> overlooking something - I cannot change the date format. When I change >> the field "DTE" to a date_format in the query as below, my date >> results are blank. Looking at the code below, can someone please >> suggest what I might be doing incorrectly? Any is greatly >> appreciated - >> >> **** >> mysql_connect("localhost", "username", "password") or >> die(mysql_error()); >> mysql_select_db("stjojone_primary") or die(mysql_error()); >> $data = mysql_query("SELECT >> LTRGCL_DTE,date_format(DTE,'%W,%M,%D,%Y'),BLTN_FIL E FROM >> bulletin_store ORDER BY DTE DESC LIMIT 0,1") or die(mysql_error()); >> Print "<div align=center><table class=\"SJTableInfo\">"; >> Print "<tr><td align=center><h5>Date</h5></td><td >> align=center><h5>Liturgical Date</h5></td></tr>"; >> while($info = mysql_fetch_array( $data )) >> { >> Print "<tr>"; >> Print "<td class=\"SJTdInfo\" align=\"center\">".$info['DTE'] . >> "</td><td class=\"SJTdInfo\" align=\"left\"><a >> href=/bulletin_files/".$info['BLTN_FILE'] ." title=\"Click to view or >> download the file\" target=\"_blank\">".$info['LTRGCL_DTE'] >> ."</a></td>"; >> } >> Print "</table></div></br></br>"; >> **** > > Ok, I changed to "date_format(DTE,'%W,%M %D,%Y') as 'DTE',", and seems > to work perfectly now. Then I find that it sorts on the literal date, > not the actual date value now! Is there an easy enough fix for that, > or should one just sort on the ID autonumber column? > Of course it does - you overrode the column name and used the results of the call to date_format(). Just change it to date_format(DTE,'%W,%M %D,%Y') as DTE2. Still order by DTE. Or, if you're not using the column name, just leave the AS DTE off entirely (I don't know what you're doing with it afterwards). -- ================== Remove the "x" from my email address Jerry Stuckle JDS Computer Training Corp. jstucklex@attglobal.net ================== |
|
|
|
#4 |
|
Messages: n/a
Hébergeur: |
Jerry Stuckle wrote:
> seastl < wrote: >> On Fri, 04 Jan 2008 20:24:53 -0600, seastl <<nospam@nospam.com>> >> wrote: >> >>> Hello, >>> >>> I am a novice (very novice) webmaster, and am trying to retrieve the >>> most recent record from a database to display on a homepage. It all >>> works well enough with one exception, which I am sure is just my >>> overlooking something - I cannot change the date format. When I >>> change the field "DTE" to a date_format in the query as below, my >>> date results are blank. Looking at the code below, can someone >>> please suggest what I might be doing incorrectly? Any is >>> greatly appreciated - >>> >>> **** >>> mysql_connect("localhost", "username", "password") or >>> die(mysql_error()); >>> mysql_select_db("stjojone_primary") or die(mysql_error()); >>> $data = mysql_query("SELECT >>> LTRGCL_DTE,date_format(DTE,'%W,%M,%D,%Y'),BLTN_FIL E FROM >>> bulletin_store ORDER BY DTE DESC LIMIT 0,1") or die(mysql_error()); >>> Print "<div align=center><table class=\"SJTableInfo\">"; >>> Print "<tr><td align=center><h5>Date</h5></td><td >>> align=center><h5>Liturgical Date</h5></td></tr>"; >>> while($info = mysql_fetch_array( $data )) >>> { >>> Print "<tr>"; >>> Print "<td class=\"SJTdInfo\" align=\"center\">".$info['DTE'] . >>> "</td><td class=\"SJTdInfo\" align=\"left\"><a >>> href=/bulletin_files/".$info['BLTN_FILE'] ." title=\"Click to view >>> or download the file\" target=\"_blank\">".$info['LTRGCL_DTE'] >>> ."</a></td>"; >>> } >>> Print "</table></div></br></br>"; >>> **** >> >> Ok, I changed to "date_format(DTE,'%W,%M %D,%Y') as 'DTE',", and >> seems to work perfectly now. Then I find that it sorts on the >> literal date, not the actual date value now! Is there an easy enough >> fix for that, or should one just sort on the ID autonumber column? >> > > Of course it does - you overrode the column name and used the results > of the call to date_format(). > > Just change it to date_format(DTE,'%W,%M %D,%Y') as DTE2. Still order > by DTE. Or, if you're not using the column name, just leave the AS > DTE off entirely (I don't know what you're doing with it afterwards). Yes you do Jerry, he is using the associative part of mysql_fetch_array() to access the value (guess he could save a bit of resource by using mysql_fetch_assoc()). Anyway, Jerry's first hint is the one to go for, coupled with changing $info['DTE'] to $info['DTE2'] |
|
![]() |
| Outils de la discussion | |
|
|