Hello i want to sort the returning data from my MySql database.

i want to sort them by their type (1,2,3)

This is what i ve done so far.

PHP works fine returns all records $somevariable represents the AND to sort the records

 function all() {
    $type = $data->type;
if($type && $type != "")
        $somevariable=" AND type='$type' ";

try {
         $db = getDB();
        $sql = "SELECT * FROM table WHERE somefield='true' $somevariable ";
        $stmt = $db->query($sql);
        $data = $stmt->fetchAll(PDO::FETCH_OBJ);
        $db = null;
        echo json_encode( $data);       


var globalFilter = {};

    $('a:not([data-filter=""])').click(function() {   
       $.extend( globalFilter, $(this).data("filter") );

    var obj = {"uid": uid,"token": token,"lastid":lastid,"perpage":perpage};
        $.extend( obj, globalFilter);
        var encodedata=JSON.stringify(obj);
        var url=apiBaseUrl+'api/all'; this calls the php script. Works Fine


<a href="#" data-filter='{"type":""}'>All</a> <a href="#type1" data-filter='{"type":"1"}'>Type 1</a> <a href="#type2" data-filter='{"type":"2"}'>Type 2</a> <a href="#type3" data-filter='{"type":"3"}'>Type 3</a>

On the table in query there is a field named type that thas 1,2,3 as values
and it returns all the data but when i press the link with the data-filter='{"type":"1"}' i want it to return only the records that have 1 as type

Member Avatar

Bit confused. The title talks of sorting - do you mean filtering?

yes i want to filter by their type