2012-11-04 36 views
2

我想重新设计一个栏的触摸屏应用程序的键盘应用程序(我正在使用Codeigniter)。用JQUERY标签显示SQL数据

我想要的文章显示在两个部分:所有article_category的 1.列出 2.下面所选择的article_category显示ARTICLE_NAME + article_price + article_image

VINES BEERS饮料< - 类别标签

白藤标签下VINES < - 不同aricle名

红葡萄

MERLOT CABERNET

我有结构SQL表的文章: 的article_id aricle_name article_category article_price article_image

寻找一个解决方案,我发现,JQUERY标签将帮助我解决问题。

我在网上找到了CI车试玩版。我用我的数据库取代了它的数据 它的工作原理与标签相同!我列出了标签中列出的所有类别。

但我不知道如何获取选定选项卡的数据(看看category.php)?

我的文件:应用程序/控制器/ cart.php

<?php 
    class Cart extends Controller { // Our Cart class extends the Controller class 
     function Cart() 
     { 
      parent::Controller(); // We define the the Controller class is the parent. 

      $this->load->model('cart_model'); // Load our cart model for our entire class 
     } 
     function index() 
     { 
      $data['categories'] = $this->cart_model->retrieve_category(); // Retrieve an array with all categories 
      $data['products'] = $this->cart_model->retrieve_products(); // Retrieve an array with all products 
      $data['content'] = 'cart/categories'; // Select view to display 
      $this->load->view('index', $data); // Display the page 
     } 
    } 

我的文件:应用程序/模型/ cart_model.php

<?php 
class Cart_model extends Model { 
    // Function to retrieve an array with all product information 
    function retrieve_products(){ 
     $query = $this->db->get('phppos_item_kits'); 
     return $query->result_array(); 
    } 
    // Function to retrieve an array with all product information 
    function retrieve_category(){ 
     $this->db->select('distinct(category)'); 
     $this->db->from('phppos_item_kits'); 
     $query = $this->db->get(); 
     return $query->result_array(); 
    } 
} 

我的文件:应用程序/视图/车/ categories.php

<head> 
<link href="<?php echo base_url(); ?>assets/js/base/jquery-ui.css" media="screen" rel="stylesheet" type="text/css"/> 
<script type="text/javascript" src="<?php echo base_url(); ?>assets/js/jquery-1.8.2.js"></script> 
<script type="text/javascript" src="<?php echo base_url(); ?>assets/js/base/jquery-ui.js"></script> 
    <script> 
    $(document).ready(function() { 
    $("#tabs").tabs({event: "mouseover"}); 
    }); 
    </script> 
</head> 
<div id="tabs"> 
    <ul> 
    <?php foreach($categories as $c): ?> 
     <li><a href="#fragment"><span><?php echo $c['category']; ?></span></a></li> 
    <?php endforeach;?> 
    </ul> 
     <div id="fragment"> 
     <?php foreach($products as $p): ?> 
       <li><?php echo $p['name']; ?>,<?php echo $p['category']; ?></li> 
     <?php endforeach;?> 
     </div> 
</div> 

我的文件:应用程序/视图/ index.php文件

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> 
<html xml:lang="en-us" xmlns="http://www.w3.org/1999/xhtml"> 
<head> 
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 
<title>CodeIgniter Shopping Cart</title> 
<link href="<?php echo base_url(); ?>assets/js/base/jquery-ui.css" media="screen" rel="stylesheet" type="text/css"/> 
<link href="<?php echo base_url(); ?>assets/css/core.css" media="screen" rel="stylesheet" type="text/css" /> 
<script type="text/javascript" src="<?php echo base_url(); ?>assets/js/jquery-ui.min.js"></script> 
<script type="text/javascript" src="<?php echo base_url(); ?>assets/js/jquery-1.8.2.min.js"></script> 
<script type="text/javascript" src="<?php echo base_url(); ?>assets/js/core.js"></script> 
</head> 
<body> 
<div> 
    <?php $this->view($content); ?> 
</div> 
</body> 
</html> 

回答

-1

解决方案应该在PHP代码中(主要是),然后您应该相应地调整您的JavaScript。

具体而言,应为每个类别分配一个属于该类别的产品清单。 它可以用SQL或PHP完成。

有了SQL,它可以用直接的方法完成 - 一个选择类别列表,然后选择一个类别,这意味着1 + n选择问题。但对于少量类别可能是可以接受的。

或者可以用JOIN完成,这可以消除1 + n问题。 如果您需要显示空白类别,您将需要LEFT OUTER JOIN和[INNER] JOIN,如果您不需要。

希望它有帮助。告诉我,如果你需要澄清/例子。

+0

@Musa:为什么减去一个?你认为这是一个无关紧要的答案吗? –

+0

我没有投下你的答案,我编辑了它。 – Musa

+0

对不起,如果我在错误的位置回答。我在这里是新手。 –