Skip to content

output rows as array #120

@aolko

Description

@aolko

how do i output all rows as an assoc array with relations?

$ormdb_channels = $ormdb->channel()
    ->select("*")
    ->where("channel.user_id=?", $_SESSION['user_id'])
;

//Get all the fields from a query
$ormdb_channel = $ormdb_channels->fetch();
$channel_arr = (array) $ormdb_channel->getIterator();

It outputs just fine, but what if i want to output only channels with $ormdb_channels->user["username"]?
i.e.

array (size=8)
  'id' => string '1' (length=1)
  'name' => string 'testtv' (length=6)
  'desc' => null
  'slug' => string 'testtv' (length=6)
  'settings' => null
  'is_live' => string '0' (length=1)
  'qi' => string '5.0' (length=3)
  'user_id' => string '1' (length=1) // maybe even remove this
  'username' => string 'test' (length=4) // <- user["username"]

case 2: same but with a whole related user

'user' => array(...)
    'username' => string 'test' (length=4)
    [...]

Upd:

//Define the table and get all the fields
$ormdb_channels = $ormdb->channel()->select("*")->where("channel.user_id=?", $_SESSION['user_id']);
$ormdb_channel = $ormdb_channels->fetch();
$channel_arr = (array) $ormdb_channel->getIterator();
$channel_arr["user"] = (array) $ormdb_channel->user->getIterator();

still want to know a correct way (and probably my way is getting only one row/field instead of multiple)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions