Page 1 of 1

FAO: CoderGoblin - Advice on some code you gave...

Posted: Sat May 19, 2007 9:48 am
by influenceuk
Hi, this refers back to a previous post...
viewtopic.php?t=67507

I have a question regarding this code given durnng that last post...

Code: Select all

<?php
$result = mysql_query("SELECT * FROM databasetablename",$db);
echo "<table>\n";
echo"<tr><td><b>C1</b><td><b>C2</b><td><b>C3</b><td><b>C4</b></tr>\n";
while ($myrow = mysql_fetch_assoc($result))
{
  $myrow['datecol']=preg_replace('/([0-9]+)-([0-9]+)-([0-9])+/','$3-$2-$1',$myrow['datecol']);
  $myrow['Plays']=($myrow['Plays']==-1 ? 'Yes' : 'No');
  echo "<tr><td>{$myrow['col1name']}</td><td>{$myrow['col2name']}</td><td>{$myrow['Plays']}</td><td><{$myrow['datecol']}/td></tr>\n";
}
echo "</table>";
?>

Basically its working, but its missin off part of the date
For example 18-09-2007 is being displayed as 8-09-2007 any ideas why its missing out the 1 (possibly as the 1 is a 10 and it only goes up to 9?

If any one has any ideas please let me know Cheers.

Posted: Sat May 19, 2007 9:56 am
by feyd
It may have to do with your placement of the plus sign.

Edit: is there a reason you aren't using DATE_FORMAT()?

Posted: Mon May 21, 2007 4:57 am
by influenceuk
Hi Feyd,
I am using this as it seemed to work ok.
I have tried to use the Date Format thing, but for some reason i can seem to display the date?

I am probably typing it wrong lol, using the code below as an example how would i go about using the Date format thing instead?