We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

Find the result set

Hello, I am a Chinese user, my English is not very good, I used a translation software to communicate with you, I face a problem, when I find results I'd like to add a value in the result How to set up, please? Here is my code:

$chengyuans = Jiazuchengyuan::find("jiazuid = $jiazuid");
$chengyuans -> name = 'vendor';

The data in the table is actually is not of this field.



98.9k
Accepted
answer

Jiazuchengyuan::find does return a resultset, you have to do something like:

$chengyuans = Jiazuchengyuan::find("jiazuid = $jiazuid");
foreach ($chengyuans as $chengyuan) {
    $chengyuans->name = 'vendor';
    if (!$chengyuans->save()) {
        foreach ($chengyuans->getMessages() as $message) {
            echo $message;
        }
    }
}