Welcome Guest, Not a member yet? Register   Sign In
How to fix results key from a joined query
#1

[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
        )
)
#2

[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.
#3

[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?
#4

[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.
#5

[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




Theme © iAndrew 2016 - Forum software by © MyBB