Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function seconddb() {
- global $seconddb;
- $seconddb = new wpdb('username','password','database name','localhost');
- }
- add_action('init','seconddb');
- // add the shortcode [pontoon-table], tell WP which function to call
- add_shortcode( 'pontoon-table', 'pontoon_table_shortcode' );
- // add the shortcode [pontoon-table], tell WP which function to call
- add_shortcode( 'pontoon-table', 'pontoon_table_shortcode' );
- // this function generates the shortcode output
- function pontoon_table_shortcode( $args ) {
- global $seconddb;
- // Shortcodes RETURN content, so store in a variable to return
- $content = '<table>';
- $content .= '</tr><th>Week Beginning</th><th>Data Type</th><th>Monday</th><th>Tuesday</th><th>Wednesday</th><th>Thursday</th><th>Friday</th><th>Saturday</th><th>Sunday</th><th>Weekly Total</th><th>Previous Week Totals</th></tr>';
- $results = $seconddb->get_results( ' SELECT * FROM seconddb_PontoonBoats_LineOne_2Log' );
- foreach ( $results AS $row ) {
- $content .= '<tr>';
- // Modify these to match the database structure
- $content .= '<td>' . $row->{'Week Beginning'} . '</td>';
- $content .= '<td>' . $row->{'Data Type'} . '</td>';
- $content .= '<td>' . $row->Monday . '</td>';
- $content .= '<td>' . $row->Tuesday . '</td>';
- $content .= '<td>' . $row->Wednesday . '</td>';
- $content .= '<td>' . $row->Thursday . '</td>';
- $content .= '<td>' . $row->Friday . '</td>';
- $content .= '<td>' . $row->Saturday . '</td>';
- $content .= '<td>' . $row->Sunday . '</td>';
- $content .= '<td>' . $row->{'Weekly Total'} . '</td>';
- $content .= '<td>' . $row->{'Previous Week Totals'} . '</td>';
- $content .= '</tr>';
- }
- $content .= '</table>';
- // return the table
- return $content;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement