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 如何实现从tello无人机上获取实时传输的视频流,然后将获取的视频通过yolov5进行检测
    • ¥15 WPF使用Canvas绘制矢量图问题
    • ¥15 用三极管设计一个单管共射放大电路
    • ¥15 孟德尔随机化r语言运行问题
    • ¥15 pyinstaller编译的时候出现No module named 'imp'
    • ¥15 nirs_kit中打码怎么看(打码文件是csv格式)
    • ¥15 怎么把多于硬盘空间放到根目录下
    • ¥15 Matlab问题解答有两个问题
    • ¥15 LCD12864中文显示
    • ¥15 在使用CH341SER.EXE时不小心把所有驱动文件删除了怎么解决