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

Any questions involving matching text strings to patterns - the pattern is called a "regular expression."

Moderator: General Moderators

Post Reply
influenceuk
Forum Commoner
Posts: 42
Joined: Tue May 08, 2007 7:48 am
Location: London, UK

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

Post 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.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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()?
influenceuk
Forum Commoner
Posts: 42
Joined: Tue May 08, 2007 7:48 am
Location: London, UK

Post 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?
Post Reply