php - Category product menu bar not linking -
i made category menu bar on website can click on category , see products of category, not working me , must doing wrong.
some database information: categories table: row 1: id row 2: name in products table: row: category_id
i used db helper (db_helper.php)
<?php if (!function_exists('get_categories_h')) { function get_categories_h(){ $ci = get_instance(); $categories = $ci->product_model->get_categories(); return $categories; } } ?>
this product_model file made get_categories function:
<?php defined('basepath') or exit('no direct script access allowed'); class product_model extends ci_model { public function saveproduct($data) { $this->db->insert('products', $data); $product_id = $this->db->insert_id(); return $product_id; } public function get_product_details($product_id) { $arrreturn = array(); $this->db->select('*'); $this->db->from('products'); $this->db->where('product_id', $product_id); $query = $this->db->get(); $result = $query->result_array(); if (!empty($result)) { $arrreturn = $result[0]; } return $arrreturn; } /* categories */ public function get_categories(){ $this->db->select('*'); $this->db->from('categories'); $query = $this->db->get(); $result = $query->result_array(); return $result; } } ?>
and menu bar in view file i'm loading categories.
<div class="container-fluid"> <div class="row"> <div class="col-lg-1"> <div id="categorymenu"> <center> <h3>categorieën</h3> </center> <ul class="list-group"> <?php foreach (get_categories_h() $category) : ?> <li class="list-group-item"> <a href="<?php echo $category->id; ?>"><?php echo $category['name']; ?> </a> </li> <?php endforeach; ?> </ul> </div> </div> </div> </div>
i able echo categories database links not working. hope can me, thanks!
looks creating nonsense url href value. unless 'id' field of 'categories' table contains values use "controller/method/id" scheme links creating don't go anywhere.
the 'id' field contains numbers. yes?
if so, links http://example.com/123
isn't going go anywhere unless have controller named "123".
you need hrefs go somewhere. recommend using anchor()
function of codeigniter url helper. need load helper before example work.
<?php foreach (get_categories_h() $category) : ?> <li class="list-group-item"> <?php echo anchor("controller_name/controller_method/{$category->id}", $category['name']); ?> </li> <?php endforeach; ?>
without anchor()
function written
<a href="controller_name/controller_method/<?php echo $category->id;?>"> <?php echo $category['name']; ?></a>
Comments
Post a Comment