Welcome Guest, Not a member yet? Register   Sign In
codeigniter active record bug?
#1

[eluser]Unknown[/eluser]
Hi all

I want to know if this is a bug , or just my mistake

when i want to select two column of datetime type

this works
Code:
$this->db->select("promotion_id as pkey, code, name, DATE_FORMAT(start_date, '%d %b, %Y'), DATE_FORMAT(end_date,'%d %b %Y'), total_qty, rent_day", false);

but this doesn't works
Code:
$this->db->select("promotion_id as pkey, code, name, DATE_FORMAT(start_date, '%d %b, %Y'), DATE_FORMAT(end_date,'%d %b, %Y'), total_qty, rent_day", false);


is this a bug or what?
#2

[eluser]JHackamack[/eluser]
Right after your query runs have you echoed out:

$this->db->last_query();

are the results the same, or different for the second date format.

Also another thing to try that might be foiling it is aliasing your columsn

DATE_FORMAT(start_date, '%d %b, %Y') as start_date

I believe MySQL assigns a date_format to both columns, so one will overwrite the other.
#3

[eluser]Unknown[/eluser]
[quote author="JHackamack" date="1263423314"]Right after your query runs have you echoed out:

$this->db->last_query();

are the results the same, or different for the second date format.

Also another thing to try that might be foiling it is aliasing your columsn

DATE_FORMAT(start_date, '%d %b, %Y') as start_date

I believe MySQL assigns a date_format to both columns, so one will overwrite the other.[/quote]

If you notice carefully the code sample that I gave you, you will find the difference is only a matter of a comma

DATE_FORMAT(end_date, '%d %b %Y')

and

DATE_FORMAT(end_date, '%d %b, %Y') --> this doesn't work


yes I echoed the query (the one without a comma) and tried it on phpmyadmin to see if it is correct

the query runs OK, I got what I wanted
and when I added a comma to the date format of the second date column it also runs OK
it gives me two column of date with '%d %b, %Y'

but when I give this format to active records it failed

It only accept one '%d %b, %Y' (with comma) and one '%d %b %Y' (without comma)

my summary is
active records only accepts
DATE_FORMAT(end_date, '%d %b %Y') and DATE_FORMAT(end_date, '%d %b, %Y') in one query

it cannot accepts
DATE_FORMAT(end_date, '%d %b, %Y') and DATE_FORMAT(end_date, '%d %b, %Y')

can someone try this ? I think this is very not right to have
#4

[eluser]JHackamack[/eluser]
Deleted
#5

[eluser]danmontgomery[/eluser]
Tried this locally and both queries work fine for me, I think your problem is something else.

Code:
$this->load->database();
$res = $this->db->select("some_data, DATE_FORMAT(start_date, '%d %b, %Y'), DATE_FORMAT(end_date, '%d %b, %Y')", false)->get('test_table')->result();
echo "<xmp>";
foreach($res as $row){
    echo print_r($row, true);
}
echo "</xmp>";

Quote:stdClass Object
(
[some_data] => Test data A
[DATE_FORMAT(start_date, '%d %b, %Y')] => 14 Jan, 2010
[DATE_FORMAT(end_date, '%d %b, %Y')] => 14 Jan, 2010
)
stdClass Object
(
[some_data] => Test data B
[DATE_FORMAT(start_date, '%d %b, %Y')] => 14 Jan, 2010
[DATE_FORMAT(end_date, '%d %b, %Y')] => 14 Jan, 2010
)
stdClass Object
(
[some_data] => Test data C
[DATE_FORMAT(start_date, '%d %b, %Y')] => 14 Jan, 2010
[DATE_FORMAT(end_date, '%d %b,%Y')] => 14 Jan, 2010
)
stdClass Object
(
[some_data] => Test data D
[DATE_FORMAT(start_date, '%d %b, %Y')] => 14 Jan, 2010
[DATE_FORMAT(end_date, '%d %b, %Y')] => 14 Jan, 2010
)
#6

[eluser]JHackamack[/eluser]
[quote author="noctrum" date="1263506176"]Tried this locally and both queries work fine for me, I think your problem is something else.

Code:
$this->load->database();
$res = $this->db->select("some_data, DATE_FORMAT(start_date, '%d %b, %Y'), DATE_FORMAT(end_date, '%d %b, %Y')", false)->get('test_table')->result();
echo "<xmp>";
foreach($res as $row){
    echo print_r($row, true);
}
echo "</xmp>";

Quote:stdClass Object
(
[some_data] => Test data A
[DATE_FORMAT(start_date, '%d %b %Y')] => 14 Jan, 2010
[DATE_FORMAT(end_date, '%d %b %Y')] => 14 Jan, 2010
)
stdClass Object
(
[some_data] => Test data B
[DATE_FORMAT(start_date, '%d %b %Y')] => 14 Jan, 2010
[DATE_FORMAT(end_date, '%d %b %Y')] => 14 Jan, 2010
)
stdClass Object
(
[some_data] => Test data C
[DATE_FORMAT(start_date, '%d %b %Y')] => 14 Jan, 2010
[DATE_FORMAT(end_date, '%d %b %Y')] => 14 Jan, 2010
)
stdClass Object
(
[some_data] => Test data D
[DATE_FORMAT(start_date, '%d %b %Y')] => 14 Jan, 2010
[DATE_FORMAT(end_date, '%d %b %Y')] => 14 Jan, 2010
)
[/quote]

The problem that i see is all your dates are formatted the same way in the result, even though you specified a different format in date_format.

AKA:
%d %b %Y returns 14 Jan, 2010 in your result (where did the comma come in)
#7

[eluser]danmontgomery[/eluser]
I realized after I posted that I pasted the results without the comma rather than the results with the comma, so I tried to fix my post... Not an actual problem.




Theme © iAndrew 2016 - Forum software by © MyBB