Please help me retrieving data using JSON

Please help me retrieving data using JSON

pvs5011pvs5011 Posts: 4Questions: 0Answers: 0
edited December 2013 in General
I'm having a little difficulty
I have two sql table
Table User:
[quote]
CREATE TABLE `user` (
`id` int(11) NOT NULL auto_increment,
`name` varchar(255) NOT NULL,
`mate_id` varchar(255) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=11 ;

--
-- Dumping data for table `user`
--

INSERT INTO `user` VALUES (1, 'Jill Trust', '1');
INSERT INTO `user` VALUES (2, 'Trevor Doug', '2');
INSERT INTO `user` VALUES (3, 'Stacy Elis', '3');
INSERT INTO `user` VALUES (4, 'Phil Tip', '4');
INSERT INTO `user` VALUES (5, 'Stark Qwest', '5');
INSERT INTO `user` VALUES (6, 'Ian Bob', '6');
INSERT INTO `user` VALUES (7, 'Tom Steph', '7');
INSERT INTO `user` VALUES (8, 'Chris Rich', '8');
INSERT INTO `user` VALUES (9, 'Jill Trust', '9');
INSERT INTO `user` VALUES (10, 'Trevor Doug', '10');

[/quote]

Table Mate:
[quote]
CREATE TABLE `mate` (
`id` int(11) NOT NULL auto_increment,
`name` varchar(255) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=11 ;

--
-- Dumping data for table `mate`
--

INSERT INTO `mate` VALUES (4, 'Jill Trust');
INSERT INTO `mate` VALUES (3, 'Chris Rich');
INSERT INTO `mate` VALUES (2, 'Tom Steph');
INSERT INTO `mate` VALUES (1, 'Ian Bob');
INSERT INTO `mate` VALUES (5, 'Trevor Doug');
INSERT INTO `mate` VALUES (6, 'Stacy Elis');
INSERT INTO `mate` VALUES (7, 'Phil Tip');
INSERT INTO `mate` VALUES (8, 'Stark Qwest');
INSERT INTO `mate` VALUES (9, 'Ian Bob');
INSERT INTO `mate` VALUES (10, 'Tom Steph');
[/quote]

Script code:
[code]
$(document).ready(function() {
$('#example').dataTable( {
"bProcessing": true,
"bServerSide": true,
"sAjaxSource": "json.php"
} );
} );
[/code]
Table code:
[code]



User
Mate




Loading data from server




User
Mate



[/code]

File json.php :
[code]
<?php
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* Easy set variables
*/

/* Array of database columns which should be read and sent back to DataTables. Use a space where
* you want to insert a non-database field (for example a counter or static image)
*/
$aColumns = array( 'name', 'mate_id' );
$sIndexColumn = "id";

/* DB table to use */
$sTable = "user";

/* Database connection information */
$gaSql['user'] = "root";
$gaSql['password'] = "root";
$gaSql['db'] = "employees";
$gaSql['server'] = "localhost";

/* REMOVE THIS LINE (it just includes my SQL connection user/pass) */
//include( $_SERVER['DOCUMENT_ROOT']."/datatables/mysql.php" );


/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* If you just want to use the basic configuration for DataTables with PHP server-side, there is
* no need to edit below this line
*/

/*
* MySQL connection
*/
$gaSql['link'] = mysql_pconnect( $gaSql['server'], $gaSql['user'], $gaSql['password'] ) or
die( 'Could not open connection to server' );

mysql_select_db( $gaSql['db'], $gaSql['link'] ) or
die( 'Could not select database '. $gaSql['db'] );


/*
* Paging
*/
$sLimit = "";
if ( isset( $_GET['iDisplayStart'] ) && $_GET['iDisplayLength'] != '-1' )
{
$sLimit = "LIMIT ".intval( $_GET['iDisplayStart'] ).", ".
intval( $_GET['iDisplayLength'] );
}


/*
* Ordering
*/
$sOrder = "";
if ( isset( $_GET['iSortCol_0'] ) )
{
$sOrder = "ORDER BY ";
for ( $i=0 ; $i $iFilteredTotal,
"aaData" => array()
);

while ( $aRow = mysql_fetch_array( $rResult ) )
{
$row = array();
for ( $i=0 ; $i
[/code]
http://datatables.net/release-datatables/examples/data_sources/server_side.html

Please help me get the name of the table mate from mate through mate_id corresponding user table.
I thank you very much.

Replies

  • pvs5011pvs5011 Posts: 4Questions: 0Answers: 0
    It seems that this is a difficult problem and no one can be solved :(
  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    I wrote a Join version of the default server-side processing script a while back: http://datatables.net/dev/server_processing.txt . I haven't used it in a while though, so you might want to check it over.

    The server-side scripts are very much a template guide, and it is assumed that you will update / modify them as needed to suit your needs.

    Allan
  • pvs5011pvs5011 Posts: 4Questions: 0Answers: 0
    Thank you very much Allan, I did.
This discussion has been closed.