bluwe Posted February 25, 2007 Share Posted February 25, 2007 Hello, I'm struggling with the following bit of code... $query = "SELECT column1, column2, column3, DATE_FORMAT(column4,'%d-%m-%y'), column5 FROM table1 WHERE column1 = '$customerid'"; $result = mysql_query($query) or die ("Unable to retrieve values.".mysql_error()); $nrows = mysql_num_rows($result); for ($i=0;$i<$nrows;$i++) { $n = $i + 1; $row = mysql_fetch_array($result); extract($row); $row[DATE_FORMAT(column4, '%d-%m-%y')] = $variable; echo $variable; } I can't get the date value into $variable. Where am I going wrong? This is doing my head in! Thanks Quote Link to comment https://forums.phpfreaks.com/topic/40069-date_format-problem/ Share on other sites More sharing options...
nloding Posted February 25, 2007 Share Posted February 25, 2007 This is a little above my head, but I think you want an AS call in there somewhere ... SELECT column1, column2, column3, DATE_FORMAT(column4,'%d-%m-%y') AS col4date, column5 FROM table1 WHERE column1 = '$customerid' Not sure if I can use AS like that though ... ?? If that works, then instead of $row['DATE...'], it'd be $row['col4date']. On top of that, you're assigning $variable to $row[], not the other way around ... for ($i=0;$i<$nrows;$i++) { $n = $i + 1; $row = mysql_fetch_array($result); extract($row); $variable = $row[DATE_FORMAT(column4, '%d-%m-%y')]; echo $variable; } Quote Link to comment https://forums.phpfreaks.com/topic/40069-date_format-problem/#findComment-193798 Share on other sites More sharing options...
Daniel0 Posted February 25, 2007 Share Posted February 25, 2007 I am not exactly sure what you are trying to do, but is this it? $query = "SELECT column1, column2, column3, DATE_FORMAT(column4,'%d-%m-%y') AS column4, column5 FROM table1 WHERE column1 = '$customerid'"; $result = mysql_query($query) or die ("Unable to retrieve values.".mysql_error()); while($row = mysql_fetch_assoc($result)) { $variable = $row['column4']; echo $variable; } Quote Link to comment https://forums.phpfreaks.com/topic/40069-date_format-problem/#findComment-193863 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.