Hi,
thanks for your post.
So, the current state is that you have your data in a mySQL table? Then I have good and bad news:
Bad news: You can’t really use WP-Table Reloaded with that data, as WP-Table Reloaded uses a custom data format, and no mySQL tables. And as you already have the mySQL table and PHP code set up, there’s no real need to try it.
Good news: For the advanced features (sorting, search, pagination, …) you actually don’t need WP-Table Reloaded. You just need to external JavaScript library “DataTables”, from http://www.datatables.net. To integrate it, just follow the tutorial at http://datatables.net/blog/Getting_started_with_DataTables%3A_First_steps . You might want to check out the HiFi plugin ( http://ww.wp.xz.cn/extend/plugins/hifi/ ), which can help to add the <script> tags and calls to the page header and footer.
Regards,
Tobias
Thread Starter
jpreto
(@jpreto)
Thanks for the fast answer!
Mmmmm… I thought I had a solution with your plugin…
I tried that solution, with some modifications caused by WordPress with this tuturial:
http://datatables.net/forums/discussion/1299/apply-datatables-to-a-table-created-with-php-within-a-worpress-document./p1
But even so I can´t do it…
I do all the steps and when I put the final code, inside a WP page it comes out an error caused by the EXE-Php Plugin…
Hi,
no, sorry, WP-Table Reloaded is not really useful for mySQL tables.
Now, that solution from your link looks pretty good actually. Maybe you should try without a PHP-Exec-Plugin, i.e. in a WordPress page template in your theme?
Regards,
Tobias
Thread Starter
jpreto
(@jpreto)
I just did a quick setup using Hifi, never used it before, but it seams great!
On WP Page Editor of “/?page_id=31” I put on header with HIFI:
<?php
wp_enqueue_script('jquery');
wp_enqueue_script('jquery-ui-core');
wp_head();
?>
<script type="text/javascript" src="/script/jquery.dataTables.min.js"></script>
Then in Page content:
Here the courses contacts:
<?php $con = mysql_connect("hostname","username","password");
if (!$con){die('Could not connect: ' . mysql_error());}
mysql_select_db("gogolfstats", $con);
$result = mysql_query("SELECT * FROM clubs ORDER BY Club_Name");
echo "<table id='table31'>
<tr>
<th>Club Name</th>
<th>Country</th>
<th>City</th>
<th>Phone</th>
</tr>";
while($row = mysql_fetch_array($result))
{
echo "<tr align='center'>";
echo "<td>" . $row['Club_Name'] . "</td>";
echo "<td>" . $row['Country'] . "</td>";
echo "<td>" . $row['City'] . "</td>";
echo "<td>" . "(+" . $row['Code'] . ") " . $row['Phone'] . "</td>";
echo "</tr>";
}
echo "</table>";
mysql_close($con);
?>
<?php
jQuery(document).ready(function($) {
$("#table31").dataTable();
});
?>
And this error comes up:
Parse error: syntax error, unexpected T_FUNCTION, expecting ‘)’ in /home/content/08/9386108/html/wp-content/plugins/exec-php/includes/runtime.php(42) : eval()’d code on line 31
And now I did exactly the same on page “?33” except the final “magic” part:
<?php
jQuery(document).ready(function($) {
$("#table31").dataTable();
});
?>
And it comes out ok but without DataTables use…
If you can see anything I would realy apreciate!!!!
Thread Starter
jpreto
(@jpreto)
How can I not use the PHP-EXE in WordPress… the pages don´t execute the code…I tryed that also…
I´m such a newbie on this!!!! 🙂
Hi,
the
jQuery(document).ready(function($) {
$("#table31").dataTable();
});
part is JavaScript code, and not PHP! You must not execute that as PHP, but wrap it in <script> tags and just echo it!
And yes, just pages don’t execute any PHP code (which is good). You can however create a page template file (in your theme), which does execute PHP (because it is a plain PHP file). More on this at http://codex.ww.wp.xz.cn/Pages#Page_Templates .
The way with PHP-EXE should however also work.
Regards,
Tobias
Thread Starter
jpreto
(@jpreto)
Thanks!!! But still can´t do it… 🙁
What you are saying is for me to put at the end of WP page editor this:
<script> echo "
jQuery(document).ready(function($) {
$('#table31').dataTable();
});
"</script>
Still doesn´t work… 🙁
Thread Starter
jpreto
(@jpreto)
OK… i´m so dumb… I wasn´t pointing to the right directories where the datatables scripts were!!!!
Now it´s working with some mistakes, but now I think is just tuning! Part of the script is working at least.
Thanks for the help!!!!!
Hi,
yes, that’s what I meant with the JavaScript 🙂 And of course the folder path has to be correct, as the browser won’t find the file otherwise. So, really great to hear that it’s working now 🙂
The remaining tweaking should just consist of adjusting the options of the DataTables library in the JavaScript call.
Best wishes,
Tobias
Thread Starter
jpreto
(@jpreto)
You are the best Tobias!!!
I read a lot of your posts (trying to solve my problem) before contacting you. Your knowledge clear explanation of the solutions you propose is great.
DataTables is really a great Plugin, How nice would it be to have a simpler form of using the plugin that automatically:
1 – Copied the files to the correct folder.
2 – Generated the code on the header of the page (like HIFI).
3 – Managed the script code of the table with on/off options.
I don´t feel this would be too dificult…
Anyway, many thanks again!!!!
Hi,
thanks for your feedback. It’s nice to hear that I could help!
About your suggestion: Don’t forget that DataTables is an external JavaScript library that was not written by me 🙂 I just use it with WP-Table Reloaded.
Having a stand-alone version of a plugin that adds DataTables is not really useful in my opinion. After all, you will need some place to manage that actual table data as well. If that’s mySQL (like in your case), you will have to do a lot of custom PHP coding anyway, so adding some JS handling is doable. And for all others, there’s WP-Table Reloaded, which has the data editing and the various options of DataTables 🙂
Best wishes,
Tobias
Thread Starter
jpreto
(@jpreto)
I thought about something like your WP-Table Reloaded but more advanced.
I tried to use your Plugin but imagine that one of the option would be to create a table through PHP code. Using all the same options that your plugin has… this would solve it.
Another thing is having the Datatables script options as on/off options, this could be done in your WP-Table Reloaded… imagine in each table creation page you would have the DataTables on/off options in the lower part.
For a user it would be much simpler to use all the Datatables options.
Just thinking out loud… Cheers!!!
Hi,
I see your point, but currently I don’t feel like extending WP-Table Reloaded in this way. Also, creating tables through PHP code can only be done by advanced users, and even then, there are thousands of possibilities…
But still thanks for sharing your ideas, I really appreciate it!
Best wishes,
Tobias
Thread Starter
jpreto
(@jpreto)
Like I read more than once: Sharing is Caring!!!!
You´ve done a great job on sharing you knowledge and your work in WP-Table Reloaded.
All the best!!!!
Hi,
thanks for the kind words! Nice to hear that you like the plugin so much 🙂
All the best to you, too!
Tobias