PHP MYSQL print error.

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
kdao
Forum Newbie
Posts: 9
Joined: Fri Jun 13, 2008 11:58 am

PHP MYSQL print error.

Post by kdao »

$query = "select date_format(entry_date, '%W, %m/%d%Y - %h:%m:%s %p') from guessbook";
//$query = " select entry_date from guessbook ";
$result = mysql_query($query);
print $query."<br>";
print $result ."<br>";
while ($rows = mysql_fetch_assoc($result))
{ print $rows[entry_date]."<br>";


Why there is no out put ? Is there other way to get it work.
if $query = "select entry_date from guessbook"; The print $rows[entry_date] works fine.
How to format entry_date that works??? Thanks for any input./advice.



<?php
$user='kdao';
$pass='khaidao';
$host='localhost';
$db='kdao';
$table='guessbook';

$conn = mysql_connect($host,$user,$pass) or die(mysql_error());
mysql_select_db($db,$conn);

$query = "select date_format(entry_date, '%W, %m/%d%Y - %h:%m:%s %p') from guessbook";
//$query = " select entry_date from guessbook ";
$result = mysql_query($query);
print $query."<br>";
print $result ."<br>";
while ($rows = mysql_fetch_assoc($result))
{ print $rows[entry_date]."<br>";
}
mysql_close($conn);

?>
Dynamis
Forum Contributor
Posts: 122
Joined: Thu Jul 10, 2008 3:15 pm
Location: Indiana, US

Re: PHP MYSQL print error.

Post by Dynamis »

kdao wrote: while ($rows = mysql_fetch_assoc($result))
I personally use mysql_fetch_array, might want to try that. I would test and let you know exactly but I am not at a computer for that right now, so just throwing this out there to try and get you a timely solution. If this does not work, post again and I will answer tomorrow.
kdao
Forum Newbie
Posts: 9
Joined: Fri Jun 13, 2008 11:58 am

Re: PHP MYSQL print error.

Post by kdao »

I have tried
while ($rows = mysql_fetch_array($result))
with out result.
I'm thinking of the query problem.
I try this
$query= "select entry_date from guessbook";
$result= mysql_query($query);
...
while ( $rows = mysql_fetch_array($result)
{ print $rows[date_format('entry_date', ' %W, %m/%d/%Y %h:%m:%s %p ');];
}
what I guess is it :
[/bWarning: date_format() expects parameter 1 to be DateTime, string given in /usr/local/apache2/php/junk.php on line 21
2008-07-16 21:11:24
What I want is :
Wednesday, 07/162008 - 09:07:24 PM EST
]
Thanks. kdao.
note : mysql table guessbook, the field entry_date type datetime .
Post Reply