php in 'show and hide details'
php in 'show and hide details'
Hi there,
After spending 2 much time on figuring out how to get this working I'm hoping somebody can help
me out here...
I'm using the server sided datatable with the 'show and hide details about a particular record' option.
Now the table is build op with data from a MySQL database with table name 'products' Now I'd like to read and insert data from another mysql table (name : stock) into the show/hide option table referring to the id given by the sql table products.... here's my code so far :
Who knows how to solve this issue??
Tnhx, greets Joey
After spending 2 much time on figuring out how to get this working I'm hoping somebody can help
me out here...
I'm using the server sided datatable with the 'show and hide details about a particular record' option.
Now the table is build op with data from a MySQL database with table name 'products' Now I'd like to read and insert data from another mysql table (name : stock) into the show/hide option table referring to the id given by the sql table products.... here's my code so far :
Who knows how to solve this issue??
Tnhx, greets Joey
This discussion has been closed.
Replies
[code]
DataTables example
@import "*******/css/demo_page.css";
@import "*******/css/demo_table.css";
@import "*******/css/ColVis.css";
var oTable;
/* Formating function for row details */
function fnFormatDetails ( nTr )
{
var aData = oTable.fnGetData( nTr );
var sOut = '';
sOut += 'Titel : '+aData[2]+' '+aData[3]+'';
sOut += 'Test:testbeschrijving';
sOut += 'Extra info:stock = .... (query needed) ... products';
sOut += '';
return sOut;
}
$(document).ready(function() {
oTable = $('#example').dataTable( {
"sDom": 'C<"clear">lfrtip',
"oColVis": {
"buttonText": "*",
"aiExclude": [ 0 ],
},
"bProcessing": true,
"bServerSide": true,
"sAjaxSource": "*******/server_processing.php",
"fnServerData": fnDataTablesPipeline,
"aoColumns": [
{ "sClass": "center", "bSortable": false },
{ "sClass": "center", "bSortable": false },
null,
null,
null,
null,
{ "sClass": "center" },
{ "sClass": "center" },
],
"aoColumnDefs": [
{ "bVisible": false, "aTargets": [ 1 ] },
{ "bVisible": false, "aTargets": [ 6 ] }
],
"aaSorting": [[2, 'asc'], [3, 'asc'], [4, 'asc'], [5, 'asc'], [6, 'asc']],
} );
$('#example tbody td img').live( 'click', function () {
var nTr = this.parentNode.parentNode;
if ( this.src.match('details_close') )
{
/* This row is already open - close it */
this.src = "*******/details_open.png";
oTable.fnClose( nTr );
}
else
{
/* Open this row */
this.src = "*******/details_close.png";
oTable.fnOpen( nTr, fnFormatDetails(nTr), 'details' );
}
} );
} );
Live example
id
Merk
Model
Jaar
Kleur
Onze Prijs
Thumb
Loading data from server
id
Merk
Model
Jaar
Kleur
Onze Prijs
Thumb
[/code]
[code]
<?php
/* MySQL connection */
$gaSql['user'] = "*******";
$gaSql['password'] = "*******";
$gaSql['db'] = "*******";
$gaSql['server'] = "*******";
$gaSql['type'] = "*******";
$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 ".mysql_real_escape_string( $_GET['iDisplayStart'] ).", ".
mysql_real_escape_string( $_GET['iDisplayLength'] );
}
/* Ordering */
if ( isset( $_GET['iSortCol_0'] ) )
{
$sOrder = "ORDER BY ";
for ( $i=0 ; $i
[/code]
$query_stock = mysql_fetch_object(mysql_query("SELECT * FROM stock WHERE id = '" '+aData[1]+' "'"));
something like that.... ??!!
[code]
$query_stock = mysql_fetch_object(mysql_query("SELECT * FROM products WHERE id = '" . $aRow['id'] . "'"));
$sOutput .= '"'.str_replace('"', '\"', $query_stock->amount).'",';
[/code]
and on line 24 of above script (server_side.html) :
[code]
sOut += 'Extra info:Stock = '+aData[1]+' pcs.';
[\code]