Welcome Guest, Not a member yet? Register   Sign In
ActiveRecord - What's wrong with this statement?
#1

[eluser]stormbytes[/eluser]
I used something similar in another query.

The only difference are the single-quotes & the slash.

Tried in in SQLpro and it works fine. CI returns the second field of the query (`revisions`) just fine, but chokes on the date field.

What's wrong with this?

Code:
$rows = $this->db->select("DATE_FORMAT(`date`, '%c-%d-%y / %1:%i %p') AS Date, `revision`", FALSE)
#2

[eluser]InsiteFX[/eluser]
MySQL DATE_FORMAT

InsieFX
#3

[eluser]tonanbarbarian[/eluser]
$this->db->select only builds the select statement, it does not execute the query.
[code]$this->db->select("DATE_FORMAT(`date`, '
#4

[eluser]stormbytes[/eluser]
I realize that -

it's followed by the get() statement.

I'm gonna try MySQL DATE_FORMAT as was suggested by InstallFX
#5

[eluser]stormbytes[/eluser]
Tried it -

No go

Code:
$rows = $this->db->select("MySQL DATE_FORMAT(`date`," .$date_format." ) AS Date, `revision`", FALSE);
#6

[eluser]tonanbarbarian[/eluser]
tell us the exact query you expect it to produce
and then run the following command after the ->db->get() and see what the query is actually producing
Code:
echo $this->db->last_query();
#7

[eluser]stormbytes[/eluser]
[quote author="tonanbarbarian" date="1287901783"]tell us the exact query you expect it to produce
and then run the following command after the ->db->get() and see what the query is actually producing
Code:
echo $this->db->last_query();
[/quote]

I expect it to access the 'Revisions' table, retrieve the 'date' field, format the date field like I expressed, retrieve the revisions field, and return the data to the controller that called it.

Frankly I'm really stumped.

This query works just fine in mysql client locally -

In fact, it actually half-works in CI. It retrieves the data from the revision field but the date field is generating an error. I'm guessing it's got something to do with the single-quotes as I've executed similar functions in other queries without a problem.
#8

[eluser]stormbytes[/eluser]
Here's the result from the echo->db->last_query() operation:

Code:
SELECT DATE_FORMAT(`date`, '%c-%d-%y / %1:%i %p' ) AS Date, `revision` FROM (Revisions)

Now I'm even more stumped!

It looks PERFECT!

Why is it generating THIS error!?

Code:
A PHP Error was encountered

Severity: Notice

Message: Undefined property: stdClass::$date

Filename: views/revisions.php

Line Number: 18

Here is revisions.php
Code:
<!DOCTYPE html>

&lt;html&gt;
&lt;head&gt;
    &lt;meta content="text/html; charset=utf-8"&gt;
    &lt;title&gt;Arrow ® | Revisions&lt;/title&gt;
    &lt;?=link_tag('css/internal.css', 'stylesheet', 'text/css', '', 'screen').PHP_EOL;?&gt;
&lt;/head&gt;
&lt;body&gt;
    <p>This is my Revisions page!</p>
    <table border="0" cellspacing="5" cellpadding="5">
        <tr>
            <th>Date</th>
            <th>Revision</th>
        </tr>
        <tr>
&lt;?php foreach($rows->result() AS $row): ?&gt;
            <td>&lt;?=$row->date;?&gt;</td>
            <td>&lt;?=$row->revision;?&gt;</td>
&lt;?php endforeach; ?&gt;

&lt;?php echo $this->db->last_query(); ?&gt;
        </tr>
    </table>
&lt;/body&gt;
&lt;/html&gt;
#9

[eluser]stormbytes[/eluser]
Oh my !&#^*$^#@*&$ GOD!????

Somebody shoot me!

The stupid thing's CASE SENSITIVE!?!?

The php parser/CI didn't like that I was calling the result->field with a small 'd'

Lol 3 hours over this?!?!?!?
#10

[eluser]WanWizard[/eluser]
Variables in PHP are case sensitive.

One of the main reasons why the PHP style guide in the manual states you should stick to lowercase and use underscores, and not use CamelCase, for variable names.




Theme © iAndrew 2016 - Forum software by © MyBB