deib97
(Deib97)
1
I have code for automatic value for any field when beforeSave.
with this code :
$codes = array('111', '11101', '11102'); //can be fetch array from mysql
$new = $this->PSB_CODE;
$max = '';
foreach($codes as $code) {
if(strpos($new, $code) === 0 && strlen($code) > strlen($max))
$max = $code;
}
$this->PSB_UMUM = $max;
How to make $codes can be shown from query mysql in Yii? How to best way to show code like my codes?
Thnks
Can you try to explain a bit more clearly what it is you’re trying to achieve?
deib97
(Deib97)
3
Yes, I have a form-input with field PSB_CODE. And NEW.PSB_CODE can be checking for parent PSB_CODE. ex :
111 => parent, level 1
11101 => child 1, with 111 as parent, level 2
11102 => child 2, with 111 as parent, level 2
1110101 => child 3, with 11101 as parent, level 3
is from pstbymdb table.
I would input PSB_CODE : 1110102 => but can be detect automaticly 11101 as parent when beforeSave. Maxlength for PSB_CODE is 10.
I’m new in Yii, every i show single array i use queryScalar(), How to make $codes = array(‘111’, ‘11101’, ‘11102’) from table? 
deib97
(Deib97)
4
Finally, this my code. Case closed.
$codes1 = Pstbymdb::model()->findAll();
$codes = CHtml::listData($users, 'ID','PSB_CODE');