|
|
|
อยากจะวนลูปให้ List select Menu ให้แสดงออกมาเหมือนดังตัวอย่างยังไงครับ มึนมากครับ |
|
|
|
|
|
|
|
ใช้ Loop ซ้อน Loop ข้างในถูกต้องแล้วครับ ที่เหลือแค่เช็ค Query ครับ ว่าทำงานถูกต้องหรือไม่
|
|
|
|
|
Date :
2018-03-01 22:07:59 |
By :
mr.win |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ได้ล่ะครับผมขอบคุณครับ
Html
<div class="control-group">
<label for="exampleSelect1">Parent</label>
<div class="controls">
<select id="sub_category" class="form-control" name="sub_category">
<option></option>
<option value="0">Top Level Category</option>
<?php foreach ($categories as $cat): ?>
<option value="<?php echo $cat['id']; ?>"><?php echo $cat['name']; ?></option>
<?php endforeach; ?>
</select>
</div>
</div>
Controller
$data['categories'] = $this->Category_admin->category_get_all();
model
public function category_create($post)
{
$this->db->insert('categories', array('parent_id' => $post['sub_category'], 'name' => $post['name'],'detail' => $post['textarea'], 'date_added' => date("Y-m-d H:i:s"), 'date_edit' => date("Y-m-d H:i:s")));
//$this->db->insert('category', array('parent_id' => $post['sub_category'], 'name' => $post['name'], 'description' => $post['textarea'], 'date_added' => date("Y-m-d H:i:s"), 'date_edit' => date("Y-m-d H:i:s") ));
}
public function category_get_all($cat_id = 0)
{
$this->data = array();
$this->db->order_by('id', 'asc');
$query = $this->db->get_where(categories, array('parent_id' => $cat_id));
$counter = 0;
foreach ($query->result() as $row) {
$this->data[$counter]['id'] = $row->id;
$this->data[$counter]['parent_id'] = $row->parent_id;
$this->data[$counter]['name'] = $row->name;
$this->data[$counter]['textarea'] = $row->detail;
$this->data[$counter]['real_name'] = $row->name;
$children = $this->category_get_children($row->id, ' - ', $counter);
$counter = $counter + $children;
$counter++;
}
return $this->data;
}
public function category_get_children($id, $separator, $counter)
{
$this->db->order_by('id', 'asc');
$query = $this->db->get_where(categories, array('parent_id' => $id));
if ($query->num_rows() == 0)
{
return FALSE;
}
else
{
foreach($query->result() as $row)
{
$counter++;
$this->data[$counter]['id'] = $row->id;
$this->data[$counter]['parent_id'] = $row->parent_id;
$this->data[$counter]['name'] = $separator.$row->name;
$this->data[$counter]['textarea'] = $row->detail;
$this->data[$counter]['real_name'] = $row->name;
$children = $this->category_get_children($row->id, $separator.' - ', $counter);
if ($children != FALSE)
{
$counter = $counter + $children;
}
}
return $counter;
}
}
|
ประวัติการแก้ไข 2018-03-03 12:03:32
|
|
|
|
Date :
2018-03-03 11:58:44 |
By :
teedesign |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 01
|