Advertisement
Guest User

Untitled

a guest
Feb 21st, 2019
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.79 KB | None | 0 0
  1. function seconddb() {
  2. global $seconddb;
  3. $seconddb = new wpdb('username','password','database name','localhost');
  4. }
  5. add_action('init','seconddb');
  6. // add the shortcode [pontoon-table], tell WP which function to call
  7. add_shortcode( 'pontoon-table', 'pontoon_table_shortcode' );
  8.  
  9. // add the shortcode [pontoon-table], tell WP which function to call
  10. add_shortcode( 'pontoon-table', 'pontoon_table_shortcode' );
  11.  
  12. // this function generates the shortcode output
  13. function pontoon_table_shortcode( $args ) {
  14.  
  15. global $seconddb;
  16. // Shortcodes RETURN content, so store in a variable to return
  17. $content = '<table>';
  18. $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>';
  19. $results = $seconddb->get_results( ' SELECT * FROM seconddb_PontoonBoats_LineOne_2Log' );
  20. foreach ( $results AS $row ) {
  21. $content .= '<tr>';
  22. // Modify these to match the database structure
  23. $content .= '<td>' . $row->{'Week Beginning'} . '</td>';
  24. $content .= '<td>' . $row->{'Data Type'} . '</td>';
  25. $content .= '<td>' . $row->Monday . '</td>';
  26. $content .= '<td>' . $row->Tuesday . '</td>';
  27. $content .= '<td>' . $row->Wednesday . '</td>';
  28. $content .= '<td>' . $row->Thursday . '</td>';
  29. $content .= '<td>' . $row->Friday . '</td>';
  30. $content .= '<td>' . $row->Saturday . '</td>';
  31. $content .= '<td>' . $row->Sunday . '</td>';
  32. $content .= '<td>' . $row->{'Weekly Total'} . '</td>';
  33. $content .= '<td>' . $row->{'Previous Week Totals'} . '</td>';
  34. $content .= '</tr>';
  35. }
  36. $content .= '</table>';
  37.  
  38. // return the table
  39. return $content;
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement