Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /*
- Plugin Name: SQL Table Scrape
- Plugin URI: http://URI_Of_Page_Describing_Plugin_and_Updates
- 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.
- Version: 1.0
- Author: Miles and Uncle Brian
- Author URI: www.mgnsystems.co.uk
- License: GPL2
- */
- /* Copyright YEAR PLUGIN_AUTHOR_NAME (email : PLUGIN AUTHOR EMAIL)
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License, version 2, as
- published by the Free Software Foundation.
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
- You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
- */
- function CountyInstances($gallery=1) {
- global $wpdb;
- $sql = "SELECT DISTINCT County, COUNT(County) AS Incident FROM tblSpeedData GROUP BY County";
- $result = $wpdb->get_results($sql);
- if( $result ) {
- $output = "<table>\n<tr><td><b>County</b></td><td><b>Incidents</b></td></tr>";
- foreach ($result as $pic)
- {
- $output .= "<tr><td>" . $pic->County . "</td><td>" . $pic->Incident . "</td></tr>\n";
- }
- $output .= "</table>\n";
- }
- return $output;
- }
- function CountyInstancesOver30($gallery=1) {
- global $wpdb;
- $sql = "SELECT DISTINCT County, COUNT(County) AS Incident FROM tblSpeedData WHERE Speed > 30 GROUP BY County";
- $result = $wpdb->get_results($sql);
- if( $result ) {
- $output = "<table>\n<tr><td><b>County</b></td><td><b>Incidents</b></td></tr>";
- foreach ($result as $pic)
- {
- $output .= "<tr><td>" . $pic->County . "</td><td>" . $pic->Incident . "</td></tr>\n";
- }
- $output .= "</table>\n";
- }
- return $output;
- }
- add_shortcode('CInstO30', 'CountyInstancesOver30');
- add_shortcode('CInst', 'CountyInstances');
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement