Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

OK... Why doesn't this work?

Status
Not open for further replies.

hpicken

Technical User
Apr 12, 2001
142
AU
Running PHP 4.06 & Mysql 3.23.

If I run this query at the Mysql prompt it returns what I want. If I run it in PHP, it doesn't return anything. If I take out the date formatting I get a result.

I've tried returning the info into a php variable then using the PHP date formatting try to return the value but it doesn't recognise it and returns a 1970 year. The value stored in the Mysql field is '2001-10-1' etc.

<?php

echo &quot;<html>\n<body>&quot;;

include (&quot;config.inc&quot;);

$result = mysql_query(&quot;SELECT DATE_FORMAT(entrydate,'%D %b %Y') FROM convicts WHERE mail LIKE 'mymail%' ORDER BY entrydate DESC LIMIT 0, 1&quot;,$db);

while ($row = mysql_fetch_array($result)) {
$lastentry = $row[&quot;entrydate&quot;];
echo &quot;Last updated $lastentry\n&quot;;
}

echo &quot;</body>\n</html>&quot;;
?>
 
$lastentry = $row[&quot;entrydate&quot;];

I have a feeling if you change this to $lastentry = $row[0];
it'll behave itself.
I can't have sent that email, it says from Superuser.
 
no

do like this SELECT DATEFORMAT(...) AS entrydate FROM ...&quot;

When you do a DATEFORMAT function the query does not return the field with the name but as Expr1 or something like. Putting the AS it will rename the field to the name you choose. This problem occurs cause you use fetch_array, if you use fetch_row, afterwards, and only in this situation, you can refer to the field as $row[0] or something like this.



Anikin
Hugo Alexandre Dias
Web-Programmer
anikin_jedi@hotmail.com
 
Thanks

It works with Alias. Should have thought of that myself.

once again thanks to all
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top