EasyUI Forum
October 16, 2025, 10:43:15 AM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News:
 
   Home   Help Search Login Register  
Pages: [1]
  Print  
Author Topic: calling php OOP method that retuns a JSON  (Read 13790 times)
nbasicx
Newbie
*
Posts: 4


View Profile
« on: September 14, 2012, 01:23:48 AM »

I am try to use the example given in "Build CRUD Application with jQuery EasyUI", but this time round I have a PHP OOP function called get_data inside get_users.php i.e:

Class Users{
public function get_data() {

$rs = mysql_query("select * from users");

$items = array();
while($row = mysql_fetch_object($rs)){
    array_push($items, $row);
}
$result["rows"] = $items;

echo json_encode($result);
}
}

How do I specify the function the url section of the table tag in index.html i.e

<table id="dg" title="My Users" class="easyui-datagrid" style="width:700px;height:250px"
         url="get_users.php?get_data"
         
         toolbar="#toolbar" pagination="true"
         rownumbers="true" fitColumns="true" singleSelect="true">

Since if I put the way I have done above it's not working?
Logged
baxter
Newbie
*
Posts: 32


View Profile Email
« Reply #1 on: September 14, 2012, 11:16:26 AM »

try this:

Code:
Class Users{
   
    public function get_data() {

        $rs = mysql_query("select field1, field2 from users");

        $items = array();
        $items['rows'] = array();

        while($row = mysql_fetch_object($rs)){
            $items['rows'][] = array('field1' => $row['field1'], 'field2' => $row['field2']);
        }

        echo json_encode($items);
    }
}

When you will have a json string directly from mysql use CONCAT:
Code:
SELECT CONCAT('[',GROUP_CONCAT(CONCAT('{name:',USER.name,''),CONCAT(',email:',USER.email,'}')),']') FROM users WHERE STATUS = 'active' ORDER BY created ASC
Logged
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines Valid XHTML 1.0! Valid CSS!