dongmu5596 2016-10-15 09:06
浏览 39

使用mvc php mysql选择选项中的两列foreach

I'm very new in MVC pattern using opencart 2.3.0.2. I try to create new field for username selection for add new product. The field what i want to do is drop down list using foreach. This is what i customize.

Database user table user table

model/catalog/product/product.php file

<..some php code..>
public function getUser()
{
    $query = $this->db->query("SELECT DISTINCT username, user_id FROM " . DB_PREFIX . "user");
    return $query->row;
}
<..some php code..>

controller/catalog/controller/product.php file

<..some php code..>
public function add()
{   
   <..some php code..>
   $this->load->model('catalog/product');
   <..some php code..>
   $this->getFormAdd();
}
protected function getFormAdd() 
{
  $theLists = $this->model_catalog_product->getUser();
  $data['theLists'][] = array(
        'username' => $theLists['username'],
        'user_id' => $theLists['user_id']
   );
<..some php code..>
$this->response->setOutput($this->load->view('catalog/product_formadd', $data));
}

view/catalog/product/product_formadd.tpl

<..some html code..>
<select style="background-color: FloralWhite;" name="filter_username" id="input-username" class="form-control">
        <option value="*">Select Name</option>
        <?php foreach ($username as $usernames) { ?>
          <option value="<?php echo $user_ids; ?>" selected><?php echo $usernames; ?></option>
        <?php } ?>  
</select>
<..some html code..>

The website didnt show up the changes i done. Did i miss something out? Please help me! Fill free to ask me if miss understand. I will explain more. Thank in advance.

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
    • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
    • ¥20 有关区间dp的问题求解
    • ¥15 多电路系统共用电源的串扰问题
    • ¥15 slam rangenet++配置
    • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
    • ¥15 ubuntu子系统密码忘记
    • ¥15 保护模式-系统加载-段寄存器
    • ¥15 电脑桌面设定一个区域禁止鼠标操作
    • ¥15 求NPF226060磁芯的详细资料