CodeIgniter Forums
How to fix results key from a joined query - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: How to fix results key from a joined query (/showthread.php?tid=18952)



How to fix results key from a joined query - El Forum - 05-23-2009

[eluser]vps4[/eluser]
Code:
$query = $this->db->query('SELECT a.*, n.node_title FROM article AS a JOIN node AS n ON a.node_ID = n.ID WHERE a.ID = '.(int)$id.' LIMIT 1;');
if ($query->num_rows()) {
    $row = $query->row();
}
print_r($row);

WHY the result be
Code:
Array
(
    [article] => stdClass Object
        (
            [a.ID] => 1
            [a.node_ID] => 1
            [a.title] => the test title
            [a.content] => the test content
            [n.node_title] => category 1
        )
)

how can I fix it to
Code:
Array
(
    [article] => stdClass Object
        (
            [ID] => 1
            [node_ID] => 1
            [title] => the test title
            [content] => the test content
            [node_title] => category 1
        )
)



How to fix results key from a joined query - El Forum - 05-24-2009

[eluser]depthcharge[/eluser]
use Aliases

i.e
Code:
SELECT a.ID AS ID, n.node_title AS node_title .........

I tend to stay away from using table.* and state the field names where possible, but that's just my preference.


How to fix results key from a joined query - El Forum - 05-24-2009

[eluser]vps4[/eluser]
[quote author="depthcharge" date="1243167627"]use Aliases

i.e
Code:
SELECT a.ID AS ID, n.node_title AS node_title .........

I tend to stay away from using table.* and state the field names where possible, but that's just my preference.[/quote]

thanks for reply.
but fanit, the SQL will be too long...
any other ways?


How to fix results key from a joined query - El Forum - 05-24-2009

[eluser]TheFuzzy0ne[/eluser]
Too long for what, exactly? Last time I checked, MySQL supported, by default, it's 1MB, which should be sufficient for most queries.


How to fix results key from a joined query - El Forum - 05-24-2009

[eluser]Dam1an[/eluser]
And even if it gets to be that long (unlikely) and you're concerned about it not being readable, break it up accross multiple lines and add some structure to it