Lo que quiero es poder imprimir todos los datos de la consulta sql. Con el código que he puesto al imprimir la datatable me da el error:
Código:
DataTables warning: JSON data from server could not be parsed. This is caused by a JSON formatting error.
Este es el código de la datatable:
Código Javascript
:
Ver original<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<title>Documento sin título</title>
<script src="scripts/jquery-1.6.1.min.js" type="text/javascript"></script>
<script src="scripts/jquery.dataTables.min.js" type="text/javascript"></script>
<script src="scripts/jquery.dataTables.columnFilter.js" type="text/javascript"></script>
<script src="scripts/jquery.dataTables.pagination.js" type="text/javascript"></script>
<link href="css/demo_table_jui.css" rel="stylesheet" type="text/css">
<style type="text/css">
/* BeginOAWidget_Instance_2586523: #dataTable */
@import url("css/custom/sunny/jquery.ui.all.css");
#dataTable {padding: 0;margin:0;width:100%;}
#dataTable_wrapper{width:100%;}
#dataTable_wrapper th {cursor:pointer}
#dataTable_wrapper tr.odd {color:#000; background-color:#ffff00}
#dataTable_wrapper tr.odd:hover {color:#ffffff; background-color:#ff9900}
#dataTable_wrapper tr.odd td.sorting_1 {color:#000000; background-color:#ffcc00}
#dataTable_wrapper tr.odd:hover td.sorting_1 {color:#ffffff; background-color:#ff6600}
#dataTable_wrapper tr.even {color:#000000; background-color:#ffffff}
#dataTable_wrapper tr.even:hover, tr.even td.highlighted{color:#EEE; background-color:#cc6600}
#dataTable_wrapper tr.even td.sorting_1 {color:#000000; background-color:#cccc00}
#dataTable_wrapper tr.even:hover td.sorting_1 {color:#FFF; background-color:#cc3300}
/* EndOAWidget_Instance_2586523 */
</style>
<script type="text/xml">
<!--
<oa:widgets>
<oa:widget wid="2586523" binding="#dataTable" />
</oa:widgets>
-->
</script>
</head>
<body>
<script type="text/javascript">
// BeginOAWidget_Instance_2586523: #dataTable
$(document).ready(function() {
oTable = $('#dataTable').dataTable({
"bJQueryUI": true,
"bScrollCollapse": true,
"sScrollY": "200px",
"bAutoWidth": true,
"bPaginate": true,
"sPaginationType": "full_numbers", //full_numbers,two_button
"bStateSave": true,
"bInfo": true,
"bFilter": true,
"iDisplayLength": 10,
"bLengthChange": true,
"sAjaxSource": "datatable_1.php",
});
} );
// EndOAWidget_Instance_2586523
</script>
<table cellpadding="0" cellspacing="0" border="0" id="dataTable">
<thead>
<tr>
<th>Recambio</th>
<th>Denominación</th>
<th>Pvp</th>
<th>Coste</th>
<th>Exist/000</th>
</tr>
</thead>
<tbody>
</tbody>
</table>
</body>
</html>
Y el php que ya lo puse antes:
datatable_1.php
Código PHP:
<?php
$con=mysql_connect ("localhost","","");
mysql_select_db("Pruebas",$con);
$sql="select recambio,denominacion,coste,pvp,existencias from almacen000";
$datos=mysql_query($sql,$con);
$first = 0;//separa los elementos con una coma
$json = '{"aaData":[';
while ($row=mysql_fetch_array($datos)) {
if ($first++) $json .=',';
$json .= '["'.$row['recambio'].'",';
$json .= '"'.$row['denominacion'].'",';
$json .= '"'.$row['pvp'].'",';
$json .= '"'.$row['coste'].'",';
$json .= '"'.$row['existencias'].'"]';
}
$json .= ']}';
print $json;
?>