• 0
Votes
name

A PHP Error was encountered

Severity: Notice

Message: Undefined index: userid

Filename: views/question.php

Line Number: 191

Backtrace:

File: /var/www/html/cnasolution/site/application/views/question.php
Line: 191
Function: _error_handler

File: /var/www/html/cnasolution/site/application/controllers/Questions.php
Line: 419
Function: view

File: /var/www/html/cnasolution/site/index.php
Line: 315
Function: require_once

name Punditsdkoslkdosdkoskdo

Unable to use multiple ORDER BY in php using AJAX

Am trying to use order by date and price low to high in this statement

SELECT * FROM allpostdata WHERE sts = '1' AND mca='Vehicle' ORDER BY pdt DESC, prs ASC 

i used echo $query; to get the query and here is how i did,

looking for ORDER BY pdt DESC, is default query i want prs to be user option .

when i select order by low to high or high to low the statement changes but query does nothing, its not sorting by price

How do i sort by prs any solution?

pdt means Date and prs means Price

HTML

 

Script

$(document).ready(function () {             filter_data();             function filter_data() {                 $.post(                         "fetch.php",                         {                             action: 'fetch_data',                             cate: get_filter('cate'),                             brand: get_filter('brand'),                             model: get_filter('model'),                             sort: get_filter('sort'),                             date: get_filter('date')                         }                 )                         .done(function (data) {                             $('.filter_data').html(data);                         });             }             function get_filter(class_name) {                 var filter = [];                 $('.' + class_name + ':checked').each(function () {                     filter.push($(this).val());                 });                 return filter;             }             $('.filter_all').click(function () {                 filter_data();             });         }); 

PHP

if (isset($_POST["action"])) { $query = "SELECT * FROM allpostdata WHERE sts = '1' AND mca='Vehicle'";  if (!empty($_POST['cate'])) {     $query .= " AND sca IN (" . str_repeat("?,", count($_POST['cate']) - 1) . "?)"; } else {     $_POST['cate'] = []; // in case it is not set  }  if (!empty($_POST['brand'])) {     $query .= " AND product_brand IN (" . str_repeat("?,", count($_POST['brand']) - 1) . "?)"; } else {     $_POST['brand'] = []; // in case it is not set  }  if (!empty($_POST['model'])) {     $query .= " AND mdl IN (" . str_repeat("?,", count($_POST['model']) - 1) . "?)"; } else {     $_POST['model'] = []; // in case it is not set  } $query .= " ORDER BY pdt DESC"; if (!empty($_POST['sort'])) {     if ($_POST["sort"][0] == "ASC" || $_POST["sort"][0] == "DESC") { //simplistic whitelist         $query .= ", prs " . $_POST['sort'][0];     } } echo $query; $stmt = $conn->prepare($query); $params = array_merge($_POST['cate'], $_POST['brand'], $_POST['model']); $stmt->execute($params); $result = $stmt->fetchAll(); $total_row = $stmt->rowCount(); $output = ''; 
Download script demo [LINK] [Origin]
Download script demo [LINK 2] [Onedrive] Download script demo [LINK 2] [Google drive]