Am I missing something?

Am I missing something?

legolas8911legolas8911 Posts: 6Questions: 0Answers: 0
edited October 2010 in General
Hi guys. I want to get the data from a MySQL table, but I think i'm missing something. Here is my code, maybe you can help me figure out what's wrong. Thanks in advance.
Table.html
[code]
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">


Title




@import "../media/css/demo_table.css";
table{width:100%}


$(document).ready(function() {
$('#myTable').dataTable( {
"bProcessing": true,
"bServerSide": true,

"sAjaxSource": "server.php"
} );
} );









Nume
Prenume
Bust
Inaltime
Greutate









[/code]
and server.php
[code]
<?php
// { initialise variables
$amt=10;
$start=0;
// }
// { connect to database
function dbRow($sql){
$q=mysql_query($sql);
$r=mysql_fetch_array($q);
return $r;
}
function dbAll($sql){
$q=mysql_query($sql);
while($r=mysql_fetch_array($q))$rs[]=$r;
return $rs;
}
mysql_connect('abc','abc','abc');
mysql_select_db('form');
// }
// { count existing records
$r=dbRow('select count(nume) as c from form');
$total_records=$r['c'];
// }
// { start displaying records
echo '{"iTotalRecords":'.$total_records.',
"iTotalDisplayRecords":'.$total_records.',
"aaData":[';
$rs=dbAll("select nume,prenume,inaltime,greutate from form
order by nume limit $start,$amt");
$f=0;
foreach($rs as $r){
if($f++) echo ',';
echo '["',$r['nume'],'",
"',addslashes($r['prenume']),'",
"',$r['inaltime'],'",
"',$r['greutate'],'"]';
}
echo ']}';
?>
[/code]
when I point my browser to server.php I can see the data, but when I point my browser to table.html, all I get are the table headers :(

Replies

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    I think your script looks a little simplistic (and also will probably not be fully valid json (use http://jsonlint.com to check). Have you tried using one of the pre-built scripts and customising it for your db? For example: http://datatables.net/development/server-side/php_mysql .

    Allan
  • legolas8911legolas8911 Posts: 6Questions: 0Answers: 0
    It is a valid json, and thanks for the scripts, I will try to customise this. I will be back later with the results.
  • legolas8911legolas8911 Posts: 6Questions: 0Answers: 0
    the same output as my script, valid json again, but the html page shows only the table headers... :(
    same result
  • legolas8911legolas8911 Posts: 6Questions: 0Answers: 0
    i forgot the ending after , but I added that. Still no data, only headers
  • legolas8911legolas8911 Posts: 6Questions: 0Answers: 0
    Finally, some data. I deleted the "../" from the file path. But no CSS styling..working on it
  • legolas8911legolas8911 Posts: 6Questions: 0Answers: 0
    Got CSS, but i can't figure out why those arrows from next page and sorting don't appear...
This discussion has been closed.