我想問一下。我在使用 CodeIgniter 創建簡單輸入表單時出錯。
我的資料庫(tbl_user):
| id | name | card | initial |
| -- | ---- | ---- | ------- |
| 1 | Alex | A001 | A |
| 2 | Fern | F001 | F |
我的模型:
public function a(){
return $this->db->get_where('tbl_user',array('initial'=>'A'));
}
我的輸入表單:
<?php foreach ($a as $user_a){ ?>
<input class="form-control" placeholder="<?php echo $user_a->card 1;?>" readonly>
<?php } ?>
然后出現錯誤訊息:不支持的運算元型別:string int。我想展示的是A002。怎么做?你愿意幫助我嗎?謝謝..
uj5u.com熱心網友回復:
卡片欄位是一個字串 & 不能與整數相加。試試這個代碼
$user_a->card = 'A001';
/* Separate String and Number */
$letters = preg_replace('/[^a-zA-Z]/', '', $user_a->card);
$numbers = preg_replace('/[^0-9]/', '', $user_a->card);
$int = (int)$numbers 1; // Convert number part to integer
$num_padded = sprintf("d", $int);
echo $letters.$num_padded;
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/463117.html
上一篇:SQL日期過濾器|模型性能
下一篇:如何使我的表單在鍵盤輸入時可滾動
