0

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);       
    }

Javascript

var globalFilter = {};
$(document).ready(function()
{

    $('a:not([data-filter=""])').click(function() {   
       $("#all").html("");
       $.extend( globalFilter, $(this).data("filter") );
       newsFeed(uid,token,apiBaseUrl,baseUrl,lastid,newsfeedPerPage,feedType,public_username,groupID,messageID);
    });

    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
});

html

<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

Edited by SimonIoa: save

3
Contributors
3
Replies
39
Views
10 Months
Discussion Span
Last Post by Bachu
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.