WordPress.org

Ready to get started?Download WordPress

Forums

Shortcode
shortcode Exec PHP (6 posts)

  1. Sam
    Member
    Posted 3 years ago #

    I have few tables in the same mysql database where word press has been installed. Ihave installed plug-in "Shortcode exe PHP". Using the shortcode exec php I want to list the table data in a page or post. Let me know if there is any other plug-in that will be more useful to me.
    A help with sample code will be much appriciated.

  2. Marcel Bokhorst
    Member
    Posted 3 years ago #

    To get you started:

    global $wpdb;
    $posts = $wpdb->get_results("SELECT post_title FROM $wpdb->posts");
    foreach ($posts as $post)
    	echo $post->post_title . '<br />';

    The WordPress codex contains a lot of useful information about database access.

  3. Sam
    Member
    Posted 3 years ago #

    Thanks for the sample code and I got your code working on my page. But I modified the code as follows to look into the my real table. But the code is not showing any result. Could you please correct the code

    global $wpdb;
    $products= $wpdb->get_results("SELECT ProductName FROM $wpdb->products");
    foreach ($products as $product)
    echo $product->ProductName . '
    ';

    Thanks

  4. Marcel Bokhorst
    Member
    Posted 3 years ago #

    Try replacing $wpdb->products by the name of the table. The $wpdb object normally only defines WordPress tables, not custom tables.

  5. Sam
    Member
    Posted 3 years ago #

    The table is in the same database. Do I need to give the same prefix as of wordpress tables?
    following is the list of the tables
    Table Action Records 1 Type Collation Size Overhead
    catagory 2 MyISAM latin1_swedish_ci 2.0 KiB -
    chilly 4 MyISAM latin1_swedish_ci 2.1 KiB -
    class 32 MyISAM utf8_general_ci 3.7 KiB -
    customer 2 MyISAM latin1_swedish_ci 2.1 KiB -
    products

    299 MyISAM utf8_general_ci 33.4 KiB -
    stgorderdetails 2 MyISAM utf8_general_ci 6.1 KiB -
    stgorders 1 MyISAM utf8_general_ci 8.1 KiB -
    subcatagory 10 MyISAM utf8_general_ci 2.2 KiB -
    table 21 MyISAM utf8_general_ci 3.5 KiB -
    tmpproducts 188 MyISAM utf8_general_ci 15.6 KiB -
    user 2 MyISAM latin1_swedish_ci 2.1 KiB -
    wp_ak_twitter 0 MyISAM utf8_general_ci 1.0 KiB -
    wp_commentmeta 17 MyISAM utf8_general_ci 24.7 KiB 256 B
    wp_comments 11 MyISAM utf8_general_ci 11.2 KiB -
    wp_drp_coupon 1 MyISAM latin1_swedish_ci 3.4 KiB -
    wp_eshop_base_products 0 MyISAM utf8_general_ci 1.0 KiB -
    wp_eshop_countries 190 MyISAM utf8_general_ci 12.1 KiB -
    wp_eshop_discount_codes 0 MyISAM utf8_general_ci 1.0 KiB -
    wp_eshop_downloads 0 MyISAM utf8_general_ci 1.0 KiB -
    wp_eshop_download_orders 0 MyISAM utf8_general_ci 1.0 KiB -
    wp_eshop_emails 11 MyISAM utf8_general_ci 4.2 KiB -
    wp_eshop_option_names 0 MyISAM utf8_general_ci 1.0 KiB -
    wp_eshop_option_sets 0 MyISAM utf8_general_ci 1.0 KiB -
    wp_eshop_orders 0 MyISAM utf8_general_ci 1.0 KiB -
    wp_eshop_order_items 0 MyISAM utf8_general_ci 1.0 KiB -
    wp_eshop_rates 10 MyISAM utf8_general_ci 2.4 KiB -
    wp_eshop_states 153 MyISAM utf8_general_ci 11.3 KiB -
    wp_eshop_stock 0 MyISAM utf8_general_ci 1.0 KiB -
    wp_links 0 MyISAM utf8_general_ci 3.6 KiB 596 B
    wp_ngg_album 0 MyISAM utf8_general_ci 1.0 KiB -
    wp_ngg_gallery 1 MyISAM utf8_general_ci 2.1 KiB -
    wp_ngg_pictures 6 MyISAM utf8_general_ci 6.2 KiB -
    wp_options 323 MyISAM utf8_general_ci 392.9 KiB 204 B
    wp_postmeta 287 MyISAM utf8_general_ci 65.1 KiB 440 B
    wp_posts 220 MyISAM utf8_general_ci 805.8 KiB 479.8 KiB
    wp_terms 14 MyISAM utf8_general_ci 8.5 KiB -
    wp_term_relationships 17 MyISAM utf8_general_ci 3.4 KiB 21 B
    wp_term_taxonomy 15 MyISAM utf8_general_ci 4.6 KiB -
    wp_usermeta 85 MyISAM utf8_general_ci 16.9 KiB -
    wp_users 4 MyISAM utf8_general_ci 4.5 KiB 32 B
    wp_vslider 4 MyISAM latin1_swedish_ci 4.1 KiB -
    wp_woo_ratings 0 MyISAM utf8_general_ci 1.0 KiB -
    42 table(s) Sum 1,932 MyISAM latin1_swedish_ci 1.4 MiB 481.3 KiB

  6. Marcel Bokhorst
    Member
    Posted 3 years ago #

    Apparently not: products.

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic