Simple Mysql Question

Joined: 11/28/2008

Does anybody else see an error in my statement here? It's not throwing an error, but at the same time, it's not returning any values. The data is stored in datetime format: '2008-07-21 11:26:34'.

CODE
$query = mysql_query("SELECT DATE_FORMAT(date, '%W %M %D %Y'), name, complaint FROM pix_ar_ ORDER BY id DESC LIMIT 250");
Joined: 11/28/2008
Strange, I setup a table with

Strange, I setup a table with four fields (id, date, name, complaint) and performed the same query and it worked (testing done in phpMyAdmin). Maybe you could try back quoting date as it may be a reserved keyword: `date`

Who can bring a charge to God's elect? It is God who justifies!

Joined: 11/28/2008
Ok, I figured it out. For

Ok, I figured it out. For what-ever reason it wouldn't just assign the formatted value to the date element. I manually assigned it and things are working fine now:

CODE
$query = mysql_query("SELECT DATE_FORMAT(date, '%W %M %D %Y') AS cleanDate, name, complaint FROM pix_ar_ ORDER BY id DESC LIMIT 250");

I'm still not sure why it wouldn't work in the first place. That's all valid sql. Maybe this is a host setting?

Joined: 11/28/2008
That's a great question. I

That's a great question. I run into this same problem when working in an Oracle database. The client we use at work does not allow for fields that aren't named. I have to explicitly name it for the query to run. I would love to know why this is if anyone could shed some light on it.

Joined: 11/28/2008
Hi PaulI can't produce any

Hi Paul

I can't produce any problems (though it is a good idea to give your result columns a nice name /smile.gif" style="vertical-align:middle" emoid=":)" border="0" alt="smile.gif" /> )

Can you try this test code?

CODE
<?php
$dbcon = mysql_connect('localhost', 'user', 'pass');
mysql_select_db ('dbname', $dbcon);
$queryres = mysql_query("SELECT DATE_FORMAT(date, '%W %M %D %Y'), name, complaint FROM pix_ar_ ORDER BY id DESC LIMIT 250", $dbcon);
while ($row = mysql_fetch_array($queryres)) { ?>
<p><?php echo $row['DATE_FORMAT(date, \'%W %M %D %Y\')']; ?></p>
<pre><?php print_r($row); ?></pre>
<?php
} ?>

Paul Davey
Whitford Church
"Everyone who calls on the name of the Lord will be saved." Romans 10:13
"For all have sinned and fall short of the glory of God, and are justified