由于使用Ajax过滤器,我无法使用DESC对数据进行排序。
数据正确显示,但是我想对它们进行排序以显示最后添加的页面。这就是为什么我尝试添加DESC的原因,但是问题是我使用了Ajax过滤器,当我放置DESC时却什么也没显示。
SELECT products.*, products_images.filename
FROM products
INNER JOIN products_images ON
(products_images.product_id = products.id)
WHERE products_images.product_id = products.id
AND products_images.id = (SELECT MIN(id)
FROM products_images
WHERE product_id = products.id AND product_status = '1' GROUP BY products.id)
所有工作直到我在此代码末尾添加DESC为止。
答案 0 :(得分:0)
要使结果按产品ID降序排列,请尝试在末尾添加JTextField
:
import java.awt.GridLayout;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTabbedPane;
import javax.swing.JTextField;
public class SwingUI {
private final JFrame frame;
private final JTabbedPane tabbedPane;
public SwingUI(){
frame = new JFrame("Test");
frame.setSize(1000, 1000);
frame.setVisible(true);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.getContentPane().setLayout(new GridLayout(1, 1));
tabbedPane = new JTabbedPane();
tabbedPane.addTab("Login", makeLoginPanel());
tabbedPane.addTab("Login2", makeLoginPanel()); //if this is left out it works
frame.getContentPane().add(tabbedPane);
}
private JPanel makeLoginPanel(){
JPanel p = new JPanel();
p.setLayout(null);
JLabel lblName = new JLabel("Name:");
lblName.setBounds(50,50,100,30);
p.add(lblName);
JTextField x = new JTextField("text");
x.setBounds(200,200,200,200);
p.add(x);
return p;
}
}
答案 1 :(得分:0)
我只添加了rsort()来对所有产品进行排序。 但是 Dharman 方法很棒,效果很好,但是用他的方法,我无法使用ajax filer来过滤产品。 像汽车一样,过滤并仅显示BMW品牌或AUDI .. 但是此rsort()函数可以很好地工作,并且不会与filter冲突。.
distance
答案 2 :(得分:0)
这是代码的第一部分。 我们将此文件命名为getdata.php
$query = "
SELECT products.*, products_images.filename..........";
if(isset($_POST["carbody"]))
{
$carbody_filter = implode("','", $_POST["carbody"]);
$query .= "
AND carbody IN('".$carbody_filter."')
";
}
然后是index.php页面中的代码
<?php
$query = "SELECT DISTINCT(carbody) FROM products WHERE
product_status = '1' ORDER BY id DESC";
$statement = $connect->prepare($query);
$statement->execute();
$result = $statement->fetchAll();
foreach($result as $row)
{
?>
<label><input type="checkbox" class="common_selector carbody" value="<?php echo
$row['carbody']; ?>" > <?php echo $row['carbody']; ?></label><br />
<?php}?>
然后在index.php页面的末尾有js ...
$(document).ready(function(){
filter_data();
function filter_data()
{
$('.filter_data').html('<div id="loading" style="" ></div>');
var action = 'fetch_data';
var degviela = get_filter('degviela');
var ser = get_filter('ser');
$.ajax({
url:"fetch_data.php",
method:"POST",
data:{action:action, carbody:carbody, ser:ser},
success:function(data){
$('.filter_data').html(data);
}
});
}
function get_filter(class_name)
{
var filter = [];
$('.'+class_name+':checked').each(function(){
filter.push($(this).val());
});
return filter;
}
$('.common_selector').click(function(){
filter_data();
});
当我在$ query =“ SELECT ....”的末尾发布您给定的代码“ ORDER BY products.id DESC”时,index.php页面不显示产品,而是显示rsort($ result);在foreach一切正常之前,先对产品进行分类并选中复选框过滤器产品。