2017-10-05 64 views

回答

0

只要確保,$this->store->select($id)->stock返回有效數字:

$this->form_validation 
     ->set_rules(
        'your_field', 
        'Label', 
        'max_length['.$this->store->select($id)->stock.']' 

        // You can also trim it before checking length like below 
        //'trim|max_length['.$this->store->select($id)->stock.']' 
     ); 
+0

這是我的模型:功能選擇(的$ id){$返回這 - > DB-> get_where( 'store',array('id'=> $ id)) - > row(); } – user3206703

+0

@ user3206703可能存在'id'記錄可能不存在的情況,在這種情況下,如果使用'row()',然後通過' - > stock'訪問它,它可能不起作用,所以'$' row = $ this-> store-> select($ id); if(isset($ row)){$ stock = $ row-> stock; } else {/ *其他數字* /}',如果你想限制,沒有股票,那麼你可以使用'less_than [10]','max_length'是字符長度 –

+0

@ user3206703:不用謝謝,謝謝在問題解決後接受。 –