How to use your original mysql table in Wordpress post.
This time, I will show how to use (search, update, etc.) your original mysql table in WordPress post.
You know how to use mysql tables for WordPress. So, you may use some WordPress API(TAG).
But can you use your original mysql table ( not provided by WordPress ) ?
This way only uses WordPress API(TAG) too. It is very easy.
The following will show how to use WordPress API(TAG) for it.
1st step, runPHP and create table for test
1st step, you should install the plugin for use php in WordPress post.
I wrote the post before about it.( See ;WordPress in PHP to run the article )
Also, you should create original mysql table for test.
The following example, I create simple sample mysql table for test.
* You may use the following example, If you can log on your web-server by SSH (or telnet).
But if you can not log on , you should use phpAdmin. So, you should run only the following SQL for table create.
|
|
Line 1: |
-Uxxx: Specify the username. xxx is the name of the user. -Pyyy: Specify the password for your account.yyy is the password. -Dzzz: Specify the database name to use.zzz is the name of the database. Note |
|
Line 8: | Execute “create table”. sql statement.
Only two pieces of information. |
How to use your original mysql table in WordPress post
You will write php codes for operation your original mysql table in WordPress post.
The following table records removed for testing and record addition, record an example reference is made.
|
|
Line 1: | WordPress provide an object for operation mysql database. You can use use the object by declaring “Global”. |
Line 5-6: | Once you remove all the table values for test. |
Lines 10-17: | Adds you add 9 recoreds to table for test. |
Lines 19-29: | All the data in the HTML output in the form of a test table. |
The following will actually work with it.
strkey | numkey |
testkey1 | 1 |
testkey2 | 2 |
testkey3 | 3 |
testkey4 | 4 |
testkey5 | 5 |
testkey6 | 6 |
testkey7 | 7 |
testkey8 | 8 |
testkey9 | 9 |
Here is an example of execution are described in the post, also in the theme template, you can work with as well.
This example will work in WordPress post , and theme template too.
If you can use this technique, you may show original table values on WordPress post and very easy.
You might also like:
Comments
2 Responses to “How to use your original mysql table in WordPress post.”
Leave a Reply
July 19th, 2011 @ 20:51:09
Good one.This is veryhelpful for the wordpress beginners.Thanks for such a interesting tutorial.
August 4th, 2011 @ 17:55:52
This is Admin.
Thanks.