Ajax sort using two compounded dropdowns - php

Currently, I am using a nav menu to display the categories of items, using Ajax to sort/limit items shown to the chosen category, and using lazyload to display additional items on scroll.
I am wanting to change the nav menu to two button dropdowns – one for categories, and the other for locations. I would like the user to be able to sort by category OR store, independently, or by category AND store, in conjunction.
Scenario:
User chooses Category A
Category A items for ALL locations are shown
User then chooses Location A
Category A items for Location A are shown
User then chooses Location B
Category A items for Location B are shown
User then chooses Category B
– Category B items for Location B are shown
I am hoping that this can be usable in reverse order as well, i.e. if the user chooses location first, and then category.
I am knee-deep in code - aren't we all! ;) - and think I need another pair of eyes to slap me back straight! Where am I going wrong?!? TIA for the help.
FYI, currently when I select the category, it works fine. When I then select a location, it just shows that location's items within the last category, regardless of the category previously chosen, and then when I scroll, lazyload begins displaying items from all locations and all categories. If I choose the location first, it shows that location's items from the last category. Any help is much appreciated.
Here are the buttons: (include-menu)
<div class="btn-group">
<button class="btn btn-default btn-lg dropdown-toggle" type="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
Choose Category <span class="caret"></span>
</button>
<ul class="dropdown-menu">
<li'; if (!$_REQUEST || $_REQUEST['show']) { echo ' class="active"'; } echo '><a class="pawn-sort" href="?show=all">Show All</a></li>'."\n";
$result = $site->query("SELECT * FROM CATEGORIES ORDER BY NAME ASC");
while ($data = $result->fetch_array())
{
$category_id = $data['ID'];
$cats = $site->query("SELECT * FROM PRODUCTS WHERE CATEGORIES LIKE '%$category_id%'");
if ($cat = $cats->fetch_array())
{
echo '<li'; if ($category_id == $_REQUEST['category']) { echo ' class="active"'; } echo '>
' . ucwords($data['NAME']) . '
<!-- <a data-index="' . $category_id . '" name="cat" href="#">' . ucwords($data['NAME']) . '</a> -->
</li>'."\n";
}
}
echo '</ul>
</div>
<div class="btn-group">
<button class="btn btn-default btn-lg dropdown-toggle" type="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
Choose Store <span class="caret"></span>
</button>
<ul class="dropdown-menu">
<li>Show All</li>
<li class="divider"></li>
<li>location1</li>
<li>location2</li>
<li>location3</li>
<li>location4</li>
<li>location5</li>
<li>location6</li>
<li>location7</li>
</ul>
</div>
Here is where ajax gets the items and displays them: (ajax-get-items)
define('ITEMS_PER_PAGE',8);
$category = $_GET['category'] ? $_GET['category'] : null;
$kingdom = $_GET['kingdom'] ? $_GET['kingdom'] : null;
if ($kingdom)
{
$this_store = " AND STORE = '$kingdom'";
} else {
$this_store = '';
}
$page = $_GET['page'] ? ($_GET['page']) : 1;
if($page < 1)
{
$page = 1;
}
$first = $_GET['first'] ? ($_GET['first']) : 0;
$next = $page + 1;
$start = ($page - 1 ) * ITEMS_PER_PAGE;
$offset = ITEMS_PER_PAGE;
if ($category) {
$que = "SELECT * FROM PRODUCTS WHERE QUANTITY != '0' AND STATUS = '1' AND CATEGORIES LIKE '%$category%' $this_store ORDER BY DATE DESC LIMIT $start, $offset";
$queAll = "SELECT * FROM PRODUCTS WHERE QUANTITY != '0' AND STATUS = '1' AND CATEGORIES LIKE '%$category%' $this_store ORDER BY DATE DESC";
} else {
$que = "SELECT * FROM PRODUCTS WHERE QUANTITY != '0' AND STATUS = '1' $this_store ORDER BY DATE DESC LIMIT $start, $offset";
$queAll = "SELECT * FROM PRODUCTS WHERE QUANTITY != '0' AND STATUS = '1' $this_store ORDER BY DATE DESC";
}
// COUNT HOW MANY ITEMS AVAILABLE
$resultsAll = $site->query("$queAll");
$countAll = count($resultsAll->fetch_assoc());
// MAIN QUERY
$results = $site->query("$que");
$output = "";
$counter = 0;
while ($cupon = $results->fetch_array()) {
$name = $cupon['NAME'];
$price = $cupon['PRICE'];
$store = $cupon['STORE'];
$sku = $cupon['SKU'];
$upc = $cupon['UPC'];
$img_id = $cupon['IMAGE_ID'];
$notify = $cupon['NOTIFY'];
$store_sku = $cupon['STORE_SKU'];
$out = "&out=true";
$img = "img/l/{$img_id}_1.jpg";
$output .= '<div class="pin">
<div id="pin_' . $counter . '">
<div class="thumbnail" style="overflow: hidden;">
<ul class="img-list">
<li>
<a href="/buy.php?sku=' . $sku . '">
<img class="radius" src="/' . $img . '">
<span class="text-content"><span>View Product Info</span></span></a>
</li>
</ul>
<div class="caption pinkish" style="margin-top:-9px;">
<h4 class="pin-title">' . $name . '</h4>
<hr style="margin-bottom:5px;">' . "\n";
$kingdoms = $castle->query("SELECT NAME, CITY, STATE FROM KINGDOMS WHERE ID = '$store' LIMIT 1");
$kingdom = $kingdoms->fetch_array();
$output .= '#' . $store_sku . '
<span class="glyphicon glyphicon-map-marker"></span> ' . $kingdom['CITY'] . '
<hr style="margin-top:5px;margin-bottom:3px;">
<p class="pin-price">
<a href="/buy.php?sku=' . $sku . '" class="btn btn-info btn-sm pull-right btn-green" style="margin-top:3px;" role="button">
<span class="glyphicon glyphicon-search small"></span> More info
</a>
<span class="price">$' . number_format($price, 2) . '</span>
<div class="clearfix"></div>
</div>
</div>
</div>
</div>' . "\n";
$counter++;
}
$output.= '<script type="text/javascript">
var container = document.querySelector(\'#container\');
var msnry;
// initialize Masonry after all images have loaded
imagesLoaded( container, function() {
msnry = new Masonry( container, {
// options
itemSelector: \'.pin\'
});
});
</script>';
if($category)
{
if(((($page -1) * ITEMS_PER_PAGE + $counter)< $countAll) )
{
$output.= '<div id="page-nav"></div>';
} else {
$output.= "<script>$('#container').infinitescroll('unbind', {debug: true});</script>";
}
} else {
if(((($page -1) * ITEMS_PER_PAGE + $counter)< $countAll) )
{
$output.= '<div id="page-nav"></div>';
} else {
$output.= "<script>$('#container').infinitescroll('unbind', {debug: true});</script>";
}
}
echo $output;
Here is the jquery:
<script>
$('.filter').on('click',function(){
var filterValue = $(this).attr('data-filter');
$('#alist').isotope({filter: filterValue});
})
var $container = $('#container');
function customMasonry(newElements)
{
// hide new items while they are loading
var $newElems = $( newElements ).css({ opacity: 0 });
// ensure that images load before adding to masonry layout
$newElems.imagesLoaded(function(){
// show elems now they're ready
$newElems.animate({ opacity: 1 });
var msnry;
// initialize Masonry after all images have loaded
imagesLoaded( $container, function() {
msnry = new Masonry( container, {
// options
itemSelector: '.pin'
});
});
});
}
function customScroll()
{
$container.infinitescroll({
navSelector : '#page-nav', // selector for the paged navigation
debug: false,
animate : false,
errorCallback : function() {
$container.infinitescroll('destroy');
$.removeData(this);
},
nextSelector : '#page-nav:first a:first', // selector for the NEXT link (to page 2)
itemSelector : '.pin', // selector for all items you'll retrieve
loading: {
finishedMsg: '',
img: 'loading.gif',
msgText: ''
}
},
// trigger Masonry as a callback
function( newElements ) {
customMasonry(newElements)
}
);
}
$(function(){
var isMobile = window.matchMedia("only screen and (min-width: 760px)");
if (isMobile.matches) {
$("#categories").sticky({topSpacing: 70});
}
customScroll();
$('.pawn-sort').click(function(event){
$('#container').html('');
$('#container').infinitescroll('bind');
$('html, body').animate({
scrollTop: $("#container").offset().top -369
}, 0);
$url = $(this).attr('href');
var res = $url.split("&");
var cat = res[0].split("=");
var $category = cat[1];
var king = res[1].split("=");
var $kingdom = king[1];
if($category == 'all' )
{
$category = null;
}
if($kingdom == 'all' )
{
$kingdom = null;
}
$('#container').css({height:500});
$.ajax({
method: "GET",
url: "ajax-get-items.php",
data: { page: "1", category: $category, kingdom: $kingdom, first: true }
})
.done(function( msg ) {
$('#container').html("<div id='gif'><img src='loading.gif'/></div>");
setTimeout(
function()
{
$('#container').html(msg);
// Reset the plugin before intializing it again
$('#container').infinitescroll('destroy');
$('#container').data('infinitescroll', null);
// Initialize plugin
$('#container').infinitescroll(
{
state: {
isDestroyed: false,
isDone: false,
isDuringAjax : false
}
}
);
customScroll();
}, 500);
});
event.preventDefault();
})
});
</script>

Related

unable $_GET data in PDO using AJAX for product filtering

Unable to filter product using PDOamd AJAX,
Below code loads data form sql using PDO and AJAX but when i try to filter based on Brand it doesn't work. tried debug var_dump method but nothing helps.
Can someone help me to solve, how do i filter product, is there anything missing in code?
HTML
<div class="md-radio my-1">
<input type="radio" class="filter_all cate" name="cate" id="<?php echo str_replace(' ', '', $row['sca']); ?>" value="<?php echo $row['sca'] ?>">
<label for="<?php echo str_replace(' ', '', $row['sca']); ?>">
<?php echo $row['sca']; ?>
</label>
</div>
SCRIPT
$(document).ready(function () {
var flag = 0;
var fetching = false;
var done = false;
function filter_data() {
// prevent concurrent requests
if (fetching === true) {
return;
}
fetching = true;
var data = {
action: 'fetch_data',
cate: get_filter('cate'),
brand: get_filter('brand'),
model: get_filter('model'),
sort: get_filter('sort'),
date: get_filter('date'),
offset: flag,
limit: 4
};
console.log($.param(data));
$.ajax({
url: "fetch.php?" + $.param(data),
type: 'POST'
})
.done(function (data) {
console.log('data received');
$('.filter_data').append(data); // append
// we reached the end, no more data
if (data === '<h3>No Data Found</h3>') {
done = true;
}
flag += 4;
fetching = false; // allow further requests again
})
.fail(function (error) {
console.log('An error occurred while fetching', error)
// TODO: some error handling
});
}
function get_filter(class_name) {
var filter = [];
$('.' + class_name + ':checked').each(function () {
filter.push($(this).val());
});
return filter;
}
$('.filter_all').click(function () {
filter_data();
});
filter_data(); // commented out for debugging purpose
var $window = $(window);
var $document = $(document);
$window.scroll(function () {
if ((window.innerHeight + window.scrollY) >= document.body.offsetHeight - 300 && fetching === false && done === false) {
console.log('infinite scroll');
filter_data();
}
});
});
PHP
<?php
include("$_SERVER[DOCUMENT_ROOT]/include/config.php");
include("$_SERVER[DOCUMENT_ROOT]/include/function.php");
$query = "SELECT * FROM allpostdata WHERE sts = '1' AND mca='Vehicle'";
if (!empty($_GET['cate'])) {
$query .= " AND sca IN (" . str_repeat("?,", count($_GET['cate']) - 1) . "?)";
} else {
$_GET['cate'] = []; // in case it is not set
}
if (!empty($_GET['brand'])) {
$query .= " AND product_brand IN (" . str_repeat("?,", count($_GET['brand']) - 1) . "?)";
} else {
$_GET['brand'] = []; // in case it is not set
}
if (!empty($_GET['model'])) {
$query .= " AND mdl IN (" . str_repeat("?,", count($_GET['model']) - 1) . "?)";
} else {
$_GET['model'] = []; // in case it is not set
}
if (empty($_GET['sort']) || $_GET['sort'][0] == "date") {
$query .= " ORDER BY pdt DESC";
} elseif ($_GET["sort"][0] == "ASC" || $_GET["sort"][0] == "DESC") {
$query .= " ORDER BY prs " . $_GET['sort'][0];
}
if (isset($_GET['limit'])) {
if (!empty($_GET['offset'])) {
$query .= " LIMIT " . $_GET['limit'] . " OFFSET " . $_GET['offset'];
} else {
$query .= " LIMIT " . $_GET['limit'];
}
}
$stmt = $conn->prepare($query);
$params = array_merge($_GET['cate'], $_GET['brand'], $_GET['model']);
$stmt->execute($params);
$result = $stmt->fetchAll();
$total_row = $stmt->rowCount();
$output = '';
if ($total_row > 0) {
foreach ($result as $row) {
$parameter = $row['pid'];
$hashed = md5($salt . $parameter);
$output .= '<a href="/single_view.php?p=' . $row['id'] . '" class="w-xl-20 w-lg-20 col-md-3 col-6 p-1 p-lg-2">
<div class="card border-0 small">
<img class="card-img-top rounded-0" src="/upload/thumb/' . $row["im1"] . '" alt="Card image cap">
<div class="card-body pb-0 pt-2 px-0">
<h6 class="card-title text-dark text-truncate">' . ucfirst(strtolower($row['tit'])) . '</h6>
<h6 class="card-subtitle mb-1 text-muted text-truncate small">' . $row['product_brand'] . ' / ' . $row['mdl'] . '</h6>
<p class="card-text"><strong class="card-text text-dark text-truncate">₹ ' . $row['prs'] . '</strong></p>' . timeAgo($row['pdt']) . '
</div>
</div>
</a>';
}
} else {
$output = '<h3>No Data Found</h3>';
}
echo $output;
?>
You are sending data via GET query parameters despite defining the ajax call as a post. That's a security risk. Try changing your AJAX call to something like this, and replace youyr $_GET stuff to $_POST.
$.ajax({
url: '/your-form-processing-page-url-here',
type: 'POST',
data: data,
mimeType: 'multipart/form-data',
success: function(data, status, jqXHR){
alert('Hooray! All is well.');
console.log(data);
console.log(status);
console.log(jqXHR);
},
error: function(jqXHR,status,error){
// Hopefully we should never reach here
console.log(jqXHR);
console.log(status);
console.log(error);
}
});

Ajax reload frame only works once

I have a timetable on my website. The user can select multiple times. The selected time is inserted into the database and the button turns from green to red, so the user know it's disabled.
I want to do this with only a reload of div.
It does work but it work only once, when pushing the button for the second time the div doesn't refresh / reload.
Update database / refresh;
$('.updateTime').click(function(){
var getUrlParameter = function getUrlParameter(sParam) {
var sPageURL = window.location.search.substring(1),
sURLVariables = sPageURL.split('&'),
sParameterName,
i;
for (i = 0; i < sURLVariables.length; i++) {
sParameterName = sURLVariables[i].split('=');
if (sParameterName[0] === sParam) {
return sParameterName[1] === undefined ? true : decodeURIComponent(sParameterName[1]);
}
}
};
var uniqueId = $(this).attr('id');
var sdate = getUrlParameter('date');
$.ajax({
url: './ajax/reservation_insert_times.php',
type: 'POST',
data: {
uniqueId :uniqueId, sdate :sdate
},
success: function(mydiv){
$("#result").load(location.href+ ' #mydiv');
}
});
});
The code for generating the times
<div class="row" id="result">
<?
$result = array();
$query = $db->query("SELECT * FROM reservation_times WHERE datum = '" . db_escape($_GET['date']) . "' ");
while($row = mysqli_fetch_array($query)) {
$result[] = $row['time'];
}
?>
<?
$timestamp = strtotime(date("Y-m-d")." 12:00");
for ($i=0;$i<=32;$i++) {
$time = date('H:i', $timestamp);
$time .= ' UUR';
if (in_array($time, $result)) {
$color = "background-color:red !important";
}
else $color = "";
$timestamp += 15 * 60;
if (isset($checked) && $checked !='') { $color = 'background-color: red;';}?>
<div class="col-xs-4 col-md-3 col-lg-2" id="mydiv">
<button type="button" id="<?=$time;?>" class="btn btn-block btn-success btn-sm text-center" style="padding:10px; margin-bottom:10px; <?=$color;?>" onclick="" <? if (isset($checked) && $checked !='') { echo 'disabled';}?>>
<?=$time;?>
</button>
</div>
<? } ?>
</div>
The code for the reservation_availablity.php call:
$query = $db->query("SELECT * FROM reservation_times WHERE time = '".$uniqueId."'");
if(mysqli_num_rows($query) == 1) {
$remove = $db->query("DELETE FROM reservation_times WHERE time = '".$uniqueId."'");
} else {
if (isset($uniqueId) && $uniqueId !='') :
$sql = $db->query("INSERT INTO reservation_times (time, datum)
VALUES ('".$uniqueId."', '".$newDate."')");
endif;
}
Change you success method of your ajax:
$.ajax({
url: './ajax/reservation_insert_times.php',
type: 'POST',
data: {
uniqueId :uniqueId, sdate :sdate
},
success: function(mydiv){
$("#result").html(mydiv);
}
});
You are sending an ajax to get new content but then in success method instead of loading new content received as ajax response you are again loading the content of the same div. That's why it is working for the first time but will remain unchanged next time onwards.
//Wrong
$("#result").load(location.href+ ' #mydiv');
// Correct
$("#result").html(mydiv);
So, now whenever this ajax send to the server, it will update the content of div#result. And to allow user to manually refresh the content of this div as and when desired then you will have to call this ajax upon click of a button labled as Refresh Timetable.

Livesearch using php and ajax not working

I have a Ajax PHP MySQL live search that basically pulls out manufacturing items from a MySQL database and presents them in a drop-down list, as users enter they search term, one item per line, just like searching in Google.
What I need is a way to allow users to click on a particular link item, and for that to display data on the same page, just below the item(link) clicked.
Any help would be appreciated.
1.HTML form
<form class="navbar-form navbar-left" action="javascript:">
<div class="input-group">
<input type="text" class="form-control" id="searchbox1" name="q" token="<?=$csrf->token()?>" action='search1' placeholder="Search for Templates" autocomplete="off">
<div class="input-group-btn">
<button class="btn btn-default " id="searchbtn1" type="submit">
<i class="fa fa-search"></i></button>
</div>
</div>
<div id="livesearch1"></div>
</form>
2. AJAX Call seperate .js file
$('#searchbox1').on('keyup focus', function(e) {
var b = $(this).attr();
delete b.class, delete b.placeholder, delete b.id, delete b.name, delete b.type, delete b.autocomplete;
b.q = $(this).val();
if (b.q != '' && b.q.length > 0) {
$.ajax({
type: "POST",
url: api,
data: b,
cache: false,
success: function(a) {
$("#livesearch1").html(a);
$("#livesearch1").fadeIn();
}
});
} else {
$("#livesearch1").fadeOut();
}
});
$('#searchbox1').on('blur', function(e) {
$('#livesearch1').fadeOut();
});
3. api call
case 'search':
if($app->isAdmin() || $app->isEditor() || $app->isUser())
{
$app->escape('q');
ob_start();
ajaxsearch($q);
echo $result = ob_get_clean();
// json('success','true','results',$result);
}
break;
4. .php file
function ajaxsearch1($q){
$db = MysqliDb::getInstance();
$csrf = new Csrf_Protect();
$q = removeWhiteSpace($q);
$q = htmlspecialchars_decode($q,ENT_QUOTES);
$q = preg_replace('/[^a-zA-Z0-9.-. .).(]/', '', $q);
if(strlen($q) >0 )
{
$term = $q;
$searchterm = explode(' ',$term);
$searchColumns = array("name","slug");
$searchCondition = '';
for($i = 0; $i < count($searchColumns); $i++)
{
$searchFieldName = $searchColumns[$i];
$searchCondition .= "($searchFieldName LIKE '%" . implode("%' AND $searchFieldName LIKE '%", $searchterm) . "%')";
if($i+1 < count($searchColumns)) $searchCondition .= " OR ";
}
$res = $db->rawQuery("SELECT * FROM tbl_templates WHERE ($searchCondition) AND (version='1') order by id desc Limit 10 ");
foreach($res as $sr)
{ ?><li><?=ucfirst($sr['name'])?></li><?php
}
}
}
?>
This was a parameter issue.
data was not in the $q it was in the $name code should be something like this.
case 'search':
if($app->isAdmin() || $app->isEditor() || $app->isUser())
{
$app->escape('name');
ob_start();
ajaxsearch($name);
echo $result = ob_get_clean();
}
break;

OpenCart 1.5.x.x ajax random value

I have dynamic block with show and hide products from table on random sort. But when the cash page is active, this part of page stom showing products and show only first product from query ... i do not understand how can i make it work with this effect and show 10 product on random soring ...
the query
$sql = "SELECT * FROM " . DB_PREFIX . "product";
$sql .= " WHERE sp_id = ".$id." AND show=1";
$sql .= " ORDER BY shop_id asc";
$query = $this->db->query($sql);
return $query->row;
and part with ajax :
<div id="content" class="group">
<div id="backItem">
<div id="footerItemContent">
</div>
<div id="footerItemDivider">-</div>
<div id="footerItemCustomer">...</div>
</div>
</div>
</div>
</div>
and my function
$(document).ready(function() {
var products = function() {
for ( var i = 0; i < complex.length; i++ ) {
var name = complex[i]['pr_name'];
var desc = complex[i]['pr_text'];
}
var i = 0;
var fnchange = function() {
$('#footerItemContent').animate({'opacity': 0}, 2000, function () {
$(this).text(desc);
}).animate({'opacity': 1}, 2500);
$('#footerItemCustomer').animate({'opacity': 0}, 2000, function () {
$(this).text(name);
}).animate({'opacity': 1}, 2500);
if( ++i < json.length ){
setTimeout(fnchange, 10000);
} else {
i = 0;
setTimeout(fnchange, 10000);
}
};
setTimeout(fnchange, 1);
};
setTimeout(feedbacks,1);
the name and desc should be an array
var names = new Array();
var desc = new Array();
for ( var i = 0; i < complex.length; i++ ) {
names[i] = complex[i]['pr_name'];
desc[i] = complex[i]['pr_text'];
}
and this
$(this).text(name[i]);
$(this).text(desc[i]);
I assume your json.length is the complex.length as the same thing

Ascending and Descending in Ionic

I have a problem in ionic.
so, when i choose the select list in "A-Z", it means ascending.
and when i click the button, it should go to another state that show my list.
if A-Z is choosen, the "goal futsal " should be number 1 right?.
how can i do that? what's wrong with my code. Please help.
thank you.
here is controller that i use in my code.
.controller('cariCtrl',function($scope,$http,$state,Cari){
$scope.cari = function(input){
Cari.setDaerah(input.daerah);
Cari.setNama(input.nama);
Cari.setUrut(input.urut);
$state.go('back.list');
}
})
.controller('listCtrl',function($scope,$http,$state,$ionicHistory,Cari){
$scope.user = [];
$scope.lapangan = [];
$scope.goBack = function(){
$state.go('menu.cari', {}, {
reload: true
});
}
$http({
method: 'POST',
data:{
daerah: Cari.getDaerah(),
nama: Cari.getNama(),
urut: Cari.getUrut()
},
url: "http://localhost/TA2/admin/app/getSearchLapangan.php"
}).success(function(data){
$scope.lapangan = data;
}).error(function(data, status,headers,config) {
alert(status);
alert(headers);
});
})
in app.js, i add this :
.factory('Cari', function(){
var data = {
daerah: '',
nama: '',
urut: ''
};
return {
getDaerah: function(){
return data.daerah;
},
setDaerah: function(pdaerah){
data.daerah = pdaerah;
},
getNama: function(){
return data.nama;
},
setNama: function(pnama){
data.nama = pnama;
},
getUrut: function(){
return data.nama;
},
setUrut: function(purut){
data.urut = purut;
}
};
})
The sql query is like this:
$daerah = $objData->daerah;
$nama = $objData->nama;
$urut = $objData->urut;
$SQL = "";
if ($urut == 0) {
$SQL = "SELECT L.*, (SELECT path FROM gambar G WHERE G.id_lapangan = L.id_lapangan LIMIT 1) as path from lapangan L WHERE daerah LIKE '" . $daerah . "%' AND nama LIKE '" . $nama . "%' ORDER BY nama ASC;";
} else {
$SQL = "SELECT L.*, (SELECT path FROM gambar G WHERE G.id_lapangan = L.id_lapangan LIMIT 1) as path from lapangan L WHERE daerah LIKE '" . $daerah . "%' AND nama LIKE '" . $nama . "%' ORDER BY nama DESC;";
}
$result = mysql_query($SQL, $link);
$array = array();
$counter = 0;
while ($row = mysql_fetch_array($result)) {
$array[$counter] = $row;
$counter++;
}
echo json_encode($array);
Here is my view :
<label class="item item-select">
<select style="right: auto;" ng-model="input.urut">
<option value="">Silahkan Pilih Urutan</option>
<option value="0">A-Z</option>
<option value="1">Z-A</option>
</select>
</label>
<button class="button button-block button-positive" ng-click="cari(input)">Cari</button>
by the way, i use php. Please help me.
You can set Ascending and Descending order list in Ionic
<label class="item item-select">
<select ng-model="input.urut" ng-change="onChange(input.urut)">
<option value="">Silahkan Pilih Urutan</option>
<option value="0">A-Z</option>
<option value="1">Z-A</option>
</select>
</label>
<div class="list">
<a ng-repeat="item in items | orderBy : 'album' : flag" href="#" class="item item-thumbnail-left">
<h2>{{ item.album }}</h2>
<h4>{{ item.artist }}</h4>
</a>
</div>
and add in your controller
$scope.flag = false;
$scope.onChange = function(urut){
if(urut == 0){
$scope.flag = false;
}else{
$scope.flag = true;
}
}
Updated Example

Categories