Mark Braspenning Tue Feb 21 14:55:40 -0500 2012

Subject: Working with active records in combination with a table with array like column names

My table looks like this:

tablename {
  id: int,
  column[1]: text,
  column[2]: text,
  ...
  column[10]: text
}

The way I now access the data in the table is via the following method:

1 $tempdata = array();
2 foreach(tablename->attributes() as $key ->$value)
3 {
4   $tempdata[$key] = $value
5 }

Now I can start working with the table data. But this feels very wrong,plus updating the data in the table can't be done in the regular way I usually work with Active records.

When I try to access the data directly, it works for tabelname->id. But when I try to do this with the other columns: tablename->column\[1\], I get the following error message:
PHP Fatal error: Uncaught exception 'ActiveRecord\\UndefinedPropertyException' with message 'Undefined property: Tablename->column

Does anybody have a solution where I can still work with the fields in an arraylike fashion?

Mysql: Serverversie: 5.1.41-3ubuntu12.8
PHP: PHP Version 5.3.2-1ubuntu4.14


Mark Braspenning Wed Feb 22 18:08:31 -0500 2012

fixed it by renaming the columns to column_1 and than accessing them in two steps:

$columnane = 'column_' . $id;
$tablename->$columnname;

(1-1/1)