Page 1 of 1

DATE_FORMAT is flaking out

Posted: Sun Aug 18, 2002 3:22 pm
by microbus
Hi there,

I'm returning a resultset from mysql into php and i'm simply trying to format the mysql yyyy-mm-m-dd into something nicer looking.

The problem is, when i run the query in mysqlgui for windows it return everything properly, but when i try to return the result to my php and print it out, i get errors...

Can someone point me in the right direction?

Here's my code:

Code: Select all

$query = "SELECT DATE_FORMAT(itemdue, '%M %d %y') as tdate FROM calendar";

$result = mysql_query($query, $conn);
$num_rows= mysql_num_rows($result);
     if ($num_rows != 0) {
         while ($row = mysql_fetch_row($result)) {
	$theDate = $rowї'tdate'];
	$showData = "$showData<tr><td class='text-normal'>$theDate</td></tr>";
	&#125;
&#125;
THe error says...
Notice: Undefined index: tdate in C:\php\calendar.php on line 487

Thanks in advance for any guidance[/b]

Posted: Sun Aug 18, 2002 3:42 pm
by fatalcure
thats because your using mysql_fetch_row, which gets a result row as an enumerated array, in other words, numbers, as in $row[0], $row[1], ect.

you need to use mysql_fetch_assoc() or mysql_fetch_array()

Posted: Sun Aug 18, 2002 4:34 pm
by microbus
Hey thanks for the fast reply.

I figured i was doing someting wrong in the return call so this makes a lot of sense...

I'm still working out my php kinks, so this is good trial and error(so to speak)!