我正在创建一个客户谁销售定制毕业齿轮定制电子商务系统。我有我的产品布局的以下屏幕截图...

我在页面的右边有一个最大的价格,颜色和材料的形式。当您单击Update options时,它会通过jquery的ajax函数将所有数据发送到我的codeigniter控制器,在那里我需要提取一个新的产品列表,其中包含他们选择的选项,并且在他们选择的价格范围内。然后,我将products数组传递给codeigniter视图,并使用ajax成功变量将该视图返回给购物车。
所以我可以只用颜色,或者只用材料,但我的问题是如何找出一套拥有我需要的所有材料和选择的产品。我想我就是想不出最好的办法。我想过拉出一个颜色正确的列表,然后是一个材料正确的列表,然后是一个定价正确的列表,然后删除合并数组中的重复项,但我觉得这不是最好的方法。
这个特定的客户端只需要" color“和" material”作为选项,因此我的products表被设置为在products表中包含颜色的id和材料的id。然后我有一个颜色和材料表,里面有id和颜色,或者id和材质。
你们觉得最好的办法是什么?我想使用codeigniters活动记录来做mysql的事情。
/编辑/
以下是我的产品表的图像:

另外,下面是我的jquery,它控制向codeigniter控制器提交数据:
//Filter Options Ajax$('#updateOptions').click(function(event) {
//Prevent the default href action
event.preventDefault();
var filterOptions = $('#filterForm').serialize();
//Get the site url
var siteUrl = $('#siteUrl').val();
//Roll up the product listing div and show a loader
$('div.products').slideUp( 500, 'easeInExpo' );
$('div.loader').delay(500).fadeIn();
//Get a new list of products and repopulate the information
$.ajax({
type: "POST",
url: siteUrl + "category/filterProducts",
data: { filterOptions: filterOptions },
success: function(data) {
$('div.loader').fadeOut(500);
$('div.products').html(data).delay(500).slideDown( 500, 'easeOutExpo' );
}
});});
发布于 2012-10-19 09:12:22
如下所示:
if ($min_price = $this->input->get_post('min_price')) {
$this->db->where('price <', $min_price);
}然后url prices.php?min_price=100会将WHERE price < 100添加到您的查询中。
对于颜色(我使用|作为分隔符,但使用适合您的分隔符):
if ($colors = $this->input->get_post('colors')) {
$colors = explode($colors, '|');
$this->db->where_in('color', $colors);
}然后,url prices.php?min_price=100&colors=red|blue将添加
WHERE price < 100 AND color IN ('red', 'blue')如果您使用数组(复选框)发布您的颜色,请尝试以下操作:
if ($colors = $this->input->post('colors')) {
$this->db->where_in('color', $colors);
} elseif ($colors = $this->input->get('colors')) {
$colors = explode($colors, '|');
$this->db->where_in('color', $colors);
}这让你可以使用url或POST来添加你的颜色,这取决于你做事情的方式。
https://stackoverflow.com/questions/12965543
复制相似问题