Php 对mySQL数据库中的表数据进行排序
我有一个网站,在不同的电话上有一个数据库。我想做一个下拉列表,让消费者分类和显示/隐藏品牌后的手机。我已经创建了我想要的下拉列表,但是我的网站不是由我编写的,而且我在编程方面没有什么经验,所以我真的希望你们中的一位能够帮助我编写PHP部分的代码 我的home.php文档中有一个函数填充了一个表,整个函数如下所示:Php 对mySQL数据库中的表数据进行排序,php,jquery,html,mysql,Php,Jquery,Html,Mysql,我有一个网站,在不同的电话上有一个数据库。我想做一个下拉列表,让消费者分类和显示/隐藏品牌后的手机。我已经创建了我想要的下拉列表,但是我的网站不是由我编写的,而且我在编程方面没有什么经验,所以我真的希望你们中的一位能够帮助我编写PHP部分的代码 我的home.php文档中有一个函数填充了一个表,整个函数如下所示: public function filter() { $price = $this->input->post('price'); if ($pri
public function filter()
{
$price = $this->input->post('price');
if ($price == '3000') {
$price2 = '0';
} else if ($price == '5500') {
$price2 = '3000';
} else if ($price == '6000') {
$price = '10000';
$price2 = '3500';
}
$size = $this->input->post('size');
$type = $this->input->post('type');
$design = $this->input->post('design');
//echo "SELECT * FROM `product_info` WHERE `ac_price` > $price2 AND `ac_price` <= $price AND `design` = '$type' AND `size` = '$size' AND `type` = '$design' GROUP BY `id` ORDER BY `rating` DESC";die;
$filter = $this->queries->custom("SELECT * FROM product_info GROUP BY model ORDER BY model ASC");
if (count($filter) > 99) {
$limits = 99;
} else {
$limits = count($filter);
}
if($this->input->post('more') == 'full'){
$limits = count($filter);
}
if($this->input->post('more') == 'less'){
$limits = 99;
}
{
$rating = "";
for ($a = 0; $a < $limits; $a++) {
$detail_len = (strlen($filter[$a]->detail) > 100) ? '...' : '';
for ($b = 0; $b < $filter[$a]->rating; $b++) {
$rating .= '<span class="fa fa-star"></span>';
}
if ($filter[$a]->rating == 1) {
for ($c = 0; $c < 4; $c++) {
$rating .= '<span style="color: #a2a1a0!important;" class="fa fa-star"></span>';
}
} elseif ($filter[$a]->rating == 2) {
for ($c = 0; $c < 3; $c++) {
$rating .= '<span style="color: #a2a1a0!important;" class="fa fa-star"></span>';
}
} elseif ($filter[$a]->rating == 3) {
for ($c = 0; $c < 2; $c++) {
$rating .= '<span style="color: #a2a1a0!important;" class="fa fa-star"></span>';
}
} elseif ($filter[$a]->rating == 4) {
for ($c = 0; $c < 1; $c++) {
$rating .= '<span style="color: #a2a1a0!important;" class="fa fa-star"></span>';
}
}
echo '
<div class="col-md-4 get_attr" model="' . $filter[$a]->model . '" brand="' . $filter[$a]->brand . '" >
<div class="col-md-12">
<div class="row">
<div class="col-md-12">
</div>
<div class="col-md-12 best">
<div class="col-md-12 best-img text-center">
<img src="' . base_url() . 'uploads/' . $filter[$a]->pic . '" alt="brand-one" style="height: 180px;">
<div class="flipdiv">
<div class="rating col-md-12 text-center nopad">
' . $rating . '
</div>
</div>
<!-- Rating -->
<!-- Modal -->
</div>
<div class="col-md-12 best-detail">
<table class="table table-bordered">
<tr>
<td style="display:none;">' . $filter[$a]->brand . '</td>
<td style="display:none;">' . $filter[$a]->model . '</td>
<td style="display:none;">' . $filter[$a]->ac_price . '</td>
<td style="display:none;">' . $filter[$a]->ram . '</td>
<td style="display:none;">' . $filter[$a]->processor . '</td>
<td style="display:none;">' . $filter[$a]->size . '</td>
<td style="display:none;">' . $filter[$a]->network . '</td>
<td style="display:none;">' . $filter[$a]->pic . '</td>
<td style="display:none;">' . $filter[$a]->detail . '</td>
<td> Mærke </td>
<td id="brand" style="display:none;" class="text-right">' . $filter[0]->brand . '</td>
<td class="text-right">' . $filter[$a]->brand . '</td>
</tr>
<tr>
<td> Model </td>
<td id="model" style="display:none;" class="text-right">' . $filter[0]->model . '</td>
<td class="text-right">' . $filter[$a]->model . '</td>
</tr>
<tr>
<td>Pris</td>
<td class="text-right">' . $filter[$a]->ac_price . ',00 kr.</td>
</tr>
<tr>
<td style="vertical-align:middle!important; height:100px!important; line-height:25px!important;" colspan="2" class="text-center">' . substr($filter[$a]->detail, 0, 100) . ' ' . $detail_len . '</td>
</tr>
</table>
</div>
<div class="text-center">
<button class="btn btn-success btn-sm view_detail form-control"> Mere Information </button>
</div>
</div>
</div>
</div>
</div>
';
$rating = "";
}
}
}
在我的index.php文件中,我写了以下内容:
<section>
<div class="col-md-12">
<form>
<select name="users" onchange="showBrand(this.value)">
<option value="">Vælg Mærke:</option>
<option value="1">Samsung</option>
<option value="2">Apple</option>
<option value="3">Huawei</option>
<option value="4">Sony</option>
</select>
</form>
</div>
</section>
<script>
/* Initial Filters */
$(document).ready(function () {
$('.loader_div').fadeIn();
var type = $('.type').val();
var price = $('.price').val() ;
var size = $('.ram').val();
var design = $('.design').val();
$.post('<?php echo base_url(); ?>mobiler/home/filter',function(data) {
if (data == '') {
$('.search_section').show();
$('.no_result').show();
}
$('#filter_list').html(data);
var brand = $('.get_attr').eq(0).attr('brand');
var model = $('.get_attr').eq(0).attr('model');
/* Sorting Bar */
function showBrand(str) {
if (str == "") {
document.getElementById("txtHint").innerHTML = "";
return;
} else {
if (window.XMLHttpRequest) {
// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp = new XMLHttpRequest();
} else {
// code for IE6, IE5
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
document.getElementById("txtHint").innerHTML = this.responseText;
}
};
xmlhttp.open("GET","<?php echo base_url(); ?>mobiler/home/showBrand"+str,true);
xmlhttp.send();
}
}
</script>
Jquery脚本也处于活动状态,因为它们用于站点的其他部分
我知道这是一个非常糟糕的问题,是一个需要编程帮助的呼喊,而不是一个实际的答案,对此我很抱歉,但在两天没有任何进展之后,我不得不尝试这个
顺便说一句,我想按“品牌”分类