CodeIgniter Forums
echo field from db (mysql) when there is a space character in field name - 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: echo field from db (mysql) when there is a space character in field name (/showthread.php?tid=10383)



echo field from db (mysql) when there is a space character in field name - El Forum - 07-29-2008

[eluser]tsiger[/eluser]
Hello everyone,
I've got a DB transfered from Access and a field contains a space character in the field name (Why people do that, even in Access?)

so when i try to refer to this field:
Code:
if ($query->num_rows() > 0)
    {
           $row = $query->row();
        echo $row->Home Address;
    }

i am getting an error (seems normal).
How do i refer to this field in order to display it? quotes? any other characters? i played with it for a while but no luck (tried for example echo $row->'Home Address', doesn't work)


echo field from db (mysql) when there is a space character in field name - El Forum - 07-29-2008

[eluser]tsiger[/eluser]
Hm.. after 14 hours in front of the screen my brain is probably somewhere else..

Instead of

Code:
$row = $query->row()
echo $row->Home Address

I used

Code:
$row = $query->row_array();
echo $row['Home Address'];

Seems to be working just fine.


echo field from db (mysql) when there is a space character in field name - El Forum - 07-29-2008

[eluser]drewbee[/eluser]
This may presenst itself as a good time to update the database architecture too. Big Grin


echo field from db (mysql) when there is a space character in field name - El Forum - 07-29-2008

[eluser]tsiger[/eluser]
I just "inherited" this Access db and i am pulling my hair, really. Field naming was (and still and issue).

E.g. (took me 4 hours to figure this out)

It's a Greek database and a field is named Occupation. All good? Well it's not good as the first character "O" is the Greek "O" and the rest goes latin. The guy found out that he's typing Greek and he said "Oops it's time to switch lang" without erasing the "O" character. How i found this? Only god knows heh Big Grin