Apply DataTables to a table created with PHP within a worpress document.
Apply DataTables to a table created with PHP within a worpress document.
I am trying to apply DataTables to a table I am creating with some PHP script within Wordpress. I am relatively noobish with both PHP and Wordpress.
What I've done so far:
I am including jQuery through header.php through this script:
[code]
<?php
wp_enqueue_script('jquery');
wp_enqueue_script('jquery-ui-core');
wp_head();
?>
[/code]
I am then including the link to dataTables js in the header.php file with
[code]
[/code]
I then created a new template file for the dataTable. This template file first creates the table through some PHP script.
[code]
<?php
require_once 'login.php';
$db_server = mysql_connect("$db_hostname", "$db_username", "$db_password") or die(mysql_error());
mysql_select_db("$db_database") or die(mysql_error());
$query = "SELECT * FROM gamesInfo";
$result = mysql_query($query) or die(mysql_error());
$rows = mysql_num_rows( $result );
echo "IDNameManufacturerReleaseDateTypeEditDelete";
for ($j = 0 ; $j < $rows ; ++$j)
{
$row = mysql_fetch_row($result);
echo "";
for ($k = 0; $k < 5 ; ++$k) echo "$row[$k]";
echo "EditDelete";
echo "";
}
echo "";
?>
[/code]
After that, I am putting in the code to apply the DataTables magic to the table I create in PHP with this code.
[code]
jQuery(document).ready(function($) {
$("#gamesTable").dataTable();
});
[/code]
The problem is, I am getting a 'length' is null or not an object jquery.dataTables.min.js, line 574 character 5 in IE. Anyone have any ideas?
The page I am doing this on is at http://www.vegas-pinball.com/games-list-test/
What I've done so far:
I am including jQuery through header.php through this script:
[code]
<?php
wp_enqueue_script('jquery');
wp_enqueue_script('jquery-ui-core');
wp_head();
?>
[/code]
I am then including the link to dataTables js in the header.php file with
[code]
[/code]
I then created a new template file for the dataTable. This template file first creates the table through some PHP script.
[code]
<?php
require_once 'login.php';
$db_server = mysql_connect("$db_hostname", "$db_username", "$db_password") or die(mysql_error());
mysql_select_db("$db_database") or die(mysql_error());
$query = "SELECT * FROM gamesInfo";
$result = mysql_query($query) or die(mysql_error());
$rows = mysql_num_rows( $result );
echo "IDNameManufacturerReleaseDateTypeEditDelete";
for ($j = 0 ; $j < $rows ; ++$j)
{
$row = mysql_fetch_row($result);
echo "";
for ($k = 0; $k < 5 ; ++$k) echo "$row[$k]";
echo "EditDelete";
echo "";
}
echo "";
?>
[/code]
After that, I am putting in the code to apply the DataTables magic to the table I create in PHP with this code.
[code]
jQuery(document).ready(function($) {
$("#gamesTable").dataTable();
});
[/code]
The problem is, I am getting a 'length' is null or not an object jquery.dataTables.min.js, line 574 character 5 in IE. Anyone have any ideas?
The page I am doing this on is at http://www.vegas-pinball.com/games-list-test/
This discussion has been closed.
Replies
Regards,
Allan
this is my php code file
<?php require_once('Connections/wp33.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
if (PHP_VERSION < 6) {
$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
}
$theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
break;
}
return $theValue;
}
}
$maxRows_events_test = 10;
$pageNum_events_test = 0;
if (isset($_GET['pageNum_events_test'])) {
$pageNum_events_test = $_GET['pageNum_events_test'];
}
$startRow_events_test = $pageNum_events_test * $maxRows_events_test;
mysql_select_db($database_wp33, $wp33);
$query_events_test = "SELECT event_owner, event_status, event_name, event_start_time, event_end_time, event_start_date, event_end_date, post_content, location_id, event_category_id, group_id FROM wp_em_events";
$query_limit_events_test = sprintf("%s LIMIT %d, %d", $query_events_test, $startRow_events_test, $maxRows_events_test);
$events_test = mysql_query($query_limit_events_test, $wp33) or die(mysql_error());
$row_events_test = mysql_fetch_assoc($events_test);
if (isset($_GET['totalRows_events_test'])) {
$totalRows_events_test = $_GET['totalRows_events_test'];
} else {
$all_events_test = mysql_query($query_events_test);
$totalRows_events_test = mysql_num_rows($all_events_test);
}
$totalPages_events_test = ceil($totalRows_events_test/$maxRows_events_test)-1;
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
Untitled Document
$(document).ready(function() {
$('#serakos').dataTable();
} );
event_owner
event_status
event_name
event_start_time
event_end_time
event_start_date
event_end_date
post_content
location_id
event_category_id
group_id
<?php do { ?>
<?php echo $row_events_test['event_owner']; ?>
<?php echo $row_events_test['event_status']; ?>
<?php echo $row_events_test['event_name']; ?>
<?php echo $row_events_test['event_start_time']; ?>
<?php echo $row_events_test['event_end_time']; ?>
<?php echo $row_events_test['event_start_date']; ?>
<?php echo $row_events_test['event_end_date']; ?>
<?php echo $row_events_test['post_content']; ?>
<?php echo $row_events_test['location_id']; ?>
<?php echo $row_events_test['event_category_id']; ?>
<?php echo $row_events_test['group_id']; ?>
<?php } while ($row_events_test = mysql_fetch_assoc($events_test)); ?>
<?php
mysql_free_result($events_test);
?>