Home:ALL Converter>MongoDB inserting a record not working as it should

MongoDB inserting a record not working as it should

Ask Time:2012-04-01T01:01:03         Author:EGHDK

Json Formatter

So, I've been working on this code for some time, but I'm giving up, and reaching out for help from you guys. I've been looking at documentation for MongoDB and PHP, but I can't find anything. What I want to do is take the sample code for inserting a record:

$obj = array( "title" => "Calvin and Hobbes", "author" => "Bill Watterson" );

And re-purpose is for my project (as shown):

    $obj = array( $startCol => $startRow );

The thing is that $startCol and $startRow are arrays, and it gives me a problem every time I want to run the document. Is there something ridiculously simple I'm missing here? Thanks in advance.

Chunk of code that's giving me problems:

$maxRows= count($currentarray); //Outputs 45
$maxCols= count($currentarray[0]); //Outputs 9
$currentRow=1;
$currentCol=1;

$testing = 1;

    do {
    while ($currentCol<$maxCols){
        $startCol[] = $currentarray[0][$currentCol];
        $startRow[] = $currentarray[$currentRow][$currentCol];
        $currentCol++;
    }

    $obj = array( $startCol => $startRow );
    $collection->insert($obj);
    print_r ($collection);
    if ($currentCol==$maxCols)
    $currentCol=1;
    $currentRow++;
    $testing++;
    //echo "<br />";
    } while ($currentRow<$maxRows);

Author:EGHDK,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/9957893/mongodb-inserting-a-record-not-working-as-it-should
yy