zend-frameworkzend-dbzend-db-table

Zend insert user and set value to max()+1


My code:

public function insertMember($member) 
{   
    $maxOrderNumber = $this->select()
        ->from($this, array(new Zend_Db_Expr('max(order_number)')));

    $id = $this->insert($member, $maxOrderNumber);
    return $id;
}

I want to insert member to last position in members table and order_number entity. Tried with $maxOrderNumber but i keep getting 0 value in database.

Im using MySql. Also i have user_id with (AI) Autoincrement so i'm forced to function this way.


Solution

  • public function insertMember($member) 
    {   
        $maxOrderNumber = $this->select()
            ->from($this, array(new Zend_Db_Expr('max(order_number)')));
        $stmt = $maxOrderNumber ->query();
         $result = $stmt->fetchAll();
    
        $id = $this->insert($member, $result ['order_number']);
        return $id;
    }
    

    soemthing like that...