Jump to content

Recommended Posts

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

 

Link to comment
https://forums.phpfreaks.com/topic/40069-date_format-problem/
Share on other sites

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;
}

Link to comment
https://forums.phpfreaks.com/topic/40069-date_format-problem/#findComment-193798
Share on other sites

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;
}

Link to comment
https://forums.phpfreaks.com/topic/40069-date_format-problem/#findComment-193863
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.