Hello all,
I'm messing around with mongodb and php in my spare time and was curious how you all handled for example:
Severity: Notice
Message: Undefined index: birthday
Basically some documents have more "fields" that others, so when pulling up the records in php I receive the above type error on such records. What's the best way to handle this?
--
You received this message because you are subscribed to the Google Groups "mongodb-user" group.
To post to this group, send email to mongod...@googlegroups.com.
To unsubscribe from this group, send email to mongodb-user...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/mongodb-user?hl=en.
Sorry it's my fault I'm having a hard time asking my question.....
Let's say I do this
#1 -
$collection->insert( array('A' => 2, 'B' => 5 ) );
#2
$collection->insert( array('A' => 1, 'B' => 4, 'C' => array("C1" => 'val', "C2" => 15) ) );
#3
$records = $collection->find();
return $records
This will get two records
The first with A and B
The second with A,B,C
in my PHP page...
foreach ($records as $record)
echo $record ['A'];
echo $record ['B'];
echo $record ['C'];
}
I would get an undefined index on the first record for C as it doesn't exist. In mysql no data would exist but the index would. What I'm looking to do is avoid this error. I guess I could do....
foreach ($records as $record)
if(isset($record ['A'];)) echo $record ['A'];
if(isset($record ['B'];)) echo $record ['B'];
if(isset($record ['C'];)) echo $record ['C'];