<?php class Dbtable { function __construct() { // $this->getId(); add_action( 'admin_notices', array( $this, 'my_update_notice')); add_shortcode( 'mydbtable', array( $this, 'showmytable')); } public function showmytable() { global $wpdb; $result = $wpdb->get_results ( "SELECT * FROM khdata_devis ORDER BY id" ); ob_start(); //$code = 'Hello World'; $output = '<table> <tr> <th> name </th> <th>email</th> <th>city</th> </tr>'; foreach ( $result as $print ) { $output .='<tr> <td>"'.$print->city.'"</td> <td>"'.$print->email.'"</td> <td>21</td> </tr>';} $output .='</table>'; return $output; ob_get_clean(); } function my_update_notice() { global $wpdb; ?> <div class="updated notice"> <p><?php _e( "name of Database $wpdb->dbname", 'my_plugin_textdomain' ); ?></p> </div> <?php } }
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter