WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Display mysql table data in a wp page (26 posts)

  1. Agent047
    Member
    Posted 2 years ago #

    Hello, i am new to WordPress. My aim is to develop a standard website using wordpress(not a blog obviously). I use wordpress 3.3,mysql 5.5 and php 5.3. I need to display data from a table in mysql database on my wp page.I have created a table in the same database that wordpress was installed.(DBname-test,table_name-it_testtable: 2 columns).
    I had gone through the codex section and forums.I saw information on wpdb class and using the same with php.But i couldn't quite figure out as to where i should write the php code to retrieve the data and display it in a page.
    Kindly help me with detailed info on how to retrieve data from the database table and display it on a page, say Table-data. If using php code, please specify the filename to insert the same.I am new to php as well, so please bear with me.Thanks a ton in advance.

  2. vtxyzzy
    Member
    Posted 2 years ago #

    This sounds like it is too big a problem to be solved on this forum. You may need to hire someone to help. You can post a job request on jobs.wordpress.net.

  3. Agent047
    Member
    Posted 2 years ago #

    Hello vtxyzzy,
    Thanks for your reply.Guess what, i got it solved! No need to hire anyone ;-).

    I can explain my solution here for the newbies who end up in this post, geeks, please pardon me if this was simple stuff for you... but then iam no geek... just a newbie.

    My aim was to display data from a mysql table onto a wordpress page. I could do it using wpdb class as mentioned in the codex.But i didn't know the file where i should write this php code that contains wpdb class functions to retrieve data from mysql table.

    Hence i installed Exec-PHP plugin.(The Exec-PHP plugin executes PHP code in posts, pages and text widgets)

    Now you are free to write your php code in the page editor and get the retrieved data on your page.

    Steps to retrive data and display it on a wordpress page:
    Create a table in mysql database(assumed that you create a table in the wordpress database itself.) In my case database_name: test, table_name:it_testtable contains 2 columns: id(number(3)) and name(varchar).
    In wordpress, create a page and in the visual editor write the code(make sure you read the documentation of Exec-PHP plugin and do the required configuration mentioned,you will have to 'disable the visual editor while writing' option under Users section):

    Here is the code to retrieve data from it_testtable and display it on this page.(wpdb class is used for wordpress database,hence you need not mention the connection parameters as wpdb already has it configured to the 'test' database with the username and password):

    <?php
    
    global $wpdb;
    /* wpdb class should not be called directly.global $wpdb variable is an instantiation of the class already set up to talk to the WordPress database */ 
    
    $result = $wpdb->get_results( "SELECT * FROM it_testtable "); /*mulitple row results can be pulled from the database with get_results function and outputs an object which is stored in $result */
    
    //echo "<pre>"; print_r($result); echo "</pre>";
    /* If you require you may print and view the contents of $result object */
    
    echo "ID"."  "."Name"."<br><br>";
    foreach($result as $row)
     {
    
     echo $row->id."  ".$row->name."<br>";
    
     }
     /* Print the contents of $result looping through each row returned in the result */
    
    ?>

    Click on update button of the page created. Now you should view the created page in your website displaying the required table data.The data may not be displayed in a formatted manner.You may use html tables or other plugins to do the same. Hope this helps someone.

  4. amlan.wordpress
    Member
    Posted 2 years ago #

    Great code.Very simple but efficient.Thanks a lot.

  5. blahblahyaya
    Member
    Posted 2 years ago #

    That is a nice option. A no code solution is WP Table Reloaded, a free plugin. It allows you to build a table in admin and then insert it into any page or post via a shortcode.

    http://wordpress.org/extend/plugins/wp-table-reloaded/

  6. abcd
    Member
    Posted 2 years ago #

    hello i want to display data in my wordpress website page and i add data in one page and now this data should come automatically to another page how we can do it using database pls reply

  7. vtxyzzy
    Member
    Posted 2 years ago #

    You could create a Page for the data and use a shortcode to display it in all the places you want it.

  8. abcd
    Member
    Posted 2 years ago #

    Thanks but i made table where data inserted then after what code is to write and where in wordpress file and wordpress admin pls reply

  9. Pioneer Valley Web Design
    Member
    Posted 2 years ago #

    Or use a Desktop Publishing tool such as Windows Live Writer (where you can create tables), there are others.

  10. abcd
    Member
    Posted 2 years ago #

    sorry but i m asking for code that what is to write in wordpress files and where in wordpress admin pages

  11. Pioneer Valley Web Design
    Member
    Posted 2 years ago #

    You do not need to know code to use WYSIWYG editors...and if you do, I am missing the point of this post...and, with WLW, you can just create pages if so desired.

    You should start a new post specific to your needs.

  12. abcd
    Member
    Posted 2 years ago #

    i add jobs in one page and i want to insert into my database table and also in contact form(next page) so that what code is to write?

  13. vtxyzzy
    Member
    Posted 2 years ago #

    It is not possible for us to guess what code needs to be written or where it needs to go.

    Here is a Codex article on interfacing with the database.

    The $wpdb object can be used to read data from any table in the WordPress database, not just the standard tables that WordPress creates.

    I suggest that you create a shortcode to read the table and format the data. Then, put the shortcode in all places where you want the data to appear.

  14. abcd
    Member
    Posted 2 years ago #

    How to create footer in my wordpress theme

  15. vtxyzzy
    Member
    Posted 2 years ago #

    Here is a Codex article on Theme Development. It includes a reference to a video tutorial.

    You should also find a theme with a structure similar to yours, but including a footer and examine its code.

    Normally, the footer code is in a file named footer.php and inserted into the theme with a call to get_footer().

  16. abcd
    Member
    Posted 2 years ago #

    Hi i m using listing wordpress theme where i can add jobs name, category and so on but in database there are many tables and in one table jobs name and category column is available but still data is not present how to find the data of jobs name and category which in add in my site. pls reply

  17. vtxyzzy
    Member
    Posted 2 years ago #

    You seem to be using a paid theme, so the code is not available to us. It is not possible for us to guess what code needs to be written or where it needs to go. You should contact the theme's supplier.

    Here is a Codex article on interfacing with the database.

  18. abcd
    Member
    Posted 2 years ago #

    Hi i add header image in my theme but problem is that submenu is not coming over image thatswhy because it is hidden due to header image what to do show my submenu over the image pls reply

  19. vtxyzzy
    Member
    Posted 2 years ago #

    Please post a link to your site where the problem can be seen.

  20. abcd
    Member
    Posted 2 years ago #

    Thanks i change the theme but one issue is that i want to add calendar in widgets i have installed calendar plus plugin and shortcode of this plugin works on pages but in text widgets i add this shortcode but it doesnt work can anyone tell me what to do to add calendar in widgets for my theme

  21. vtxyzzy
    Member
    Posted 2 years ago #

    I am not familiar with that calendar plugin.

  22. abcd
    Member
    Posted 2 years ago #

    hello pls tell me how to create portfolio of images in my home page?

  23. abcd
    Member
    Posted 2 years ago #

    I want to create one of my page like http://www.tresdots.net site can any one help me out that how can we make it.

  24. vtxyzzy
    Member
    Posted 2 years ago #

    Because this thread is marked 'Resolved', not very many people will look at it. You should start a new thread with this new question.

  25. ydhe
    Member
    Posted 1 year ago #

    How to build select box which has values to be retrieved from database table

  26. vtxyzzy
    Member
    Posted 1 year ago #

    Because this thread is marked 'Resolved', not very many people will look at it. You should start a new thread with this new question.

Topic Closed

This topic has been closed to new replies.

About this Topic