koralarts
koralarts

Reputation: 2112

find() returning NULL Yii

find() is returning NULL even though there is a row that matches the criteria.

Find snippet

            $tempApp = Applicant::model()->find(array('condition'=>'phn=' . $app->phn . ' AND id<>' . $app->id));

            if($tempApp != NULL) {
                $archId = $this->archive($tempApp);
                if($archId != NULL) {
                    $tempApp->phn = NULL;
                    $tempApp->save();
                    $app->note = 'Former name: ' . $tempApp->first_name . ' ' . $tempApp->middle_name . ' ' . $tempApp->last_name;
                } else {
                    unset($archId);
                }
            }

NOTE: This code works the second time the applicant is updated. I'm confused why this is happening. Can someone give me advice as to why this is happening.

NOTE: I tried the different ways find() can be used (ie. find('phn=:phn AND id<>:id', array(':phn'=>$app->phn, ':id'=>$app->id));

Thanks

Upvotes: 0

Views: 2294

Answers (2)

Kaletha
Kaletha

Reputation: 3239

use count() instead of NULL

if(count($tempApp)) {
                $archId = $this->archive($tempApp);
                if(count($archId)) {
                    $tempApp->phn = NULL;
                    $tempApp->save();
                    $app->note = 'Former name: ' . $tempApp->first_name . ' ' . $tempApp->middle_name . ' ' . $tempApp->last_name;
                } else {
                    unset($archId);
                }
            }

Upvotes: 1

Brett Gregson
Brett Gregson

Reputation: 5913

Try echoing out your SQL statement and pasting it in phpmyadmin sql tab and see if you get a result.

Also, I would try using !empty() instead of NULL for my if statement

Upvotes: 0

Related Questions