Advertisement
Guest User

Code for Miles's Custom Plugin

a guest
Oct 8th, 2011
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.16 KB | None | 0 0
  1. <?php
  2. /*
  3. Plugin Name: SQL Table Scrape
  4. Plugin URI: http://URI_Of_Page_Describing_Plugin_and_Updates
  5. Description: This plugin allows you to write a SQL query and store it as a 'report'. You can then add these reports to a page using a shortcode.
  6. Version: 1.0
  7. Author: Miles and Uncle Brian
  8. Author URI: www.mgnsystems.co.uk
  9. License: GPL2
  10. */
  11.  
  12. /* Copyright YEAR PLUGIN_AUTHOR_NAME (email : PLUGIN AUTHOR EMAIL)
  13.  
  14. This program is free software; you can redistribute it and/or modify
  15. it under the terms of the GNU General Public License, version 2, as
  16. published by the Free Software Foundation.
  17.  
  18. This program is distributed in the hope that it will be useful,
  19. but WITHOUT ANY WARRANTY; without even the implied warranty of
  20. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  21. GNU General Public License for more details.
  22.  
  23. You should have received a copy of the GNU General Public License
  24. along with this program; if not, write to the Free Software
  25. Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  26. */
  27.  
  28. function CountyInstances($gallery=1) {
  29. global $wpdb;
  30. $sql = "SELECT DISTINCT County, COUNT(County) AS Incident FROM tblSpeedData GROUP BY County";
  31. $result = $wpdb->get_results($sql);
  32. if( $result ) {
  33. $output = "<table>\n<tr><td><b>County</b></td><td><b>Incidents</b></td></tr>";
  34. foreach ($result as $pic)
  35. {
  36. $output .= "<tr><td>" . $pic->County . "</td><td>" . $pic->Incident . "</td></tr>\n";
  37. }
  38. $output .= "</table>\n";
  39. }
  40. return $output;
  41. }
  42. function CountyInstancesOver30($gallery=1) {
  43. global $wpdb;
  44. $sql = "SELECT DISTINCT County, COUNT(County) AS Incident FROM tblSpeedData WHERE Speed > 30 GROUP BY County";
  45. $result = $wpdb->get_results($sql);
  46. if( $result ) {
  47. $output = "<table>\n<tr><td><b>County</b></td><td><b>Incidents</b></td></tr>";
  48. foreach ($result as $pic)
  49. {
  50. $output .= "<tr><td>" . $pic->County . "</td><td>" . $pic->Incident . "</td></tr>\n";
  51. }
  52. $output .= "</table>\n";
  53. }
  54. return $output;
  55. }
  56. add_shortcode('CInstO30', 'CountyInstancesOver30');
  57. add_shortcode('CInst', 'CountyInstances');
  58. ?>
  59.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement