Am I missing something?
Am I missing something?
legolas8911
Posts: 6Questions: 0Answers: 0
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 :(
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 :(
This discussion has been closed.
Replies
Allan
same result