Title1

Title2

Title3

10-1 實做

  1. 類別下拉選單,我們屆時會將類別儲存在「ugm_p_kind」資料表,當我們需要選單時,再從資料表撈出
    不過這裡,我們先用陣列來代替
    程式 - 預設值
    
      $row['kind'] = isset($row['kind']) ? $row['kind']: "";  
      $row['kind_options'] = get_kind_options($row['kind']);
    程式 - 函數(取得選項,傳入預設值,selected 代表選擇)
    
    function get_kind_options($default=""){
      global $db;
      $kind_options = array(
        "1"=>"類別1",
        "2"=>"類別2",
        "3"=>"類別3",
        "4"=>"類別4",
        "5"=>"類別5"
      );  
    
      $options = "";
      foreach($kind_options as $key=> $option){
        $selected = ($default == $key) ? " selected":"";
        $options .="<option value='{$key}'{$selected}>{$option}</option>";
      }
      return $options;
    }
    樣板
    
              <div class="col-sm-3">
                <div class="form-group">
                  <label for="kind">類別</label>
                  <select name="kind" class="form-control" size="1">
                    <{$row.kind_options}>
                  </select>
                </div>
              </div>
  2. 商品價格
    樣板
    
              <div class="col-sm-3">
                <div class="form-group">
                  <label for="price">商品價格</label>
                  <input type="text" class="form-control" id="price" name="price" value="<{$row.price}>">
                </div>            
              </div>

     

  3. 商品數量
    樣板
    
              <div class="col-sm-3">
                <div class="form-group">
                  <label for="amount">商品數量</label>
                  <input type="text" class="form-control" id="amount" name="amount" value="<{$row.amount}>">
                </div>            
              </div>
  4. 結果