Problem Implementing DataTables

Problem Implementing DataTables

edwards17edwards17 Posts: 4Questions: 0Answers: 0
edited February 2014 in General
Hi, thanks in advance for any help!

I am trying to implement datatables into my tables but I am not able to get the script to work. I am using WordPress and XAMPP to practice with.
So far the table shows up along with the demo_page.css styling which I implemented to test. I can't seem to find anything wrong with this..

Also, I read the forum rules and know that I should give a test case, but I am unsure how to do this. I do not think a test case would make much of a difference with this basic code.

Here is my code:

<?php
/** Template Name: DataTables */
$con=mysqli_connect("localhost","root","**","groceries");
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}

$result = mysqli_query($con,"SELECT * FROM groceries");

?>
<!DOCTYPE html>


DataTables





@import "http://localhost/groceries/wordpress/wp-content/DataTables/media/css/demo_table.css";



$(document).ready(function(){
$('#datatables').dataTable();
})











Store
Item
Price
Location
Select



<?php
while($row = mysqli_fetch_array($result))
{
?>

<?=$row['Store']?>
<?=$row['Item']?>
<?=$row['Price']?>
<?=$row['Location']?>


<?php
}

?>

Replies

  • tangerinetangerine Posts: 3,365Questions: 39Answers: 395
    Your HTML table id has to match your DataTable initialisation. You have "Products" and "#datatables".
  • edwards17edwards17 Posts: 4Questions: 0Answers: 0
    Thanks for the quick reply! I changed the DataTable initialization to '#Products' and still have the same result (Table is all that shows, with only partial styling from CSS file - Which is odd).
  • tangerinetangerine Posts: 3,365Questions: 39Answers: 395
    I missed that your script needs a closing semi-colon:
    [code]$('#datatables').dataTable();
    }) ; [/code]
  • edwards17edwards17 Posts: 4Questions: 0Answers: 0
    Found the error.. forgot the "t" in script.. Stupid mistake

    Thanks for the input tangerine!
  • tangerinetangerine Posts: 3,365Questions: 39Answers: 395
    You can look at something a dozen times and not see it. We've all been there!
This discussion has been closed.