• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
echo field from db (mysql) when there is a space character in field name

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

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

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

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


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.