Create a WordPress Plugin to display data in a database table

Hi Experts,

I want to develop a wordpress plugin that allows me to "manage" the database table I have created. I have a database table which contains numerous number of records, and I want the plugin to be able to add/edit/delete entries and list the entries. Also I want to display the results like a post in the front-end of the wordpress website.

Is there any possible way of doing this?

Thanks in advance.

Regards,
FeziAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

FeziAuthor Commented:
Hi Experts,

Can anyone shed some light on this topic, please? I've not found a solution for this.
0
Jason C. LevineDon't talk to me.Commented:
Hi Fezi,

Why do you want a plugin to do this?  Wouldn't it be simpler to make a page that has the code to connect to the table and forms to manage it instead of having to do the full architecture?
0
FeziAuthor Commented:
I just thought if I create a plugin to do this, i could reuse this in future sites, maybe.

If it's simpler to do the way you suggested, how do I connect the database to a table and add, etc.. I have a table with data, which I want to be displayed in seperate pages
0
Jason C. LevineDon't talk to me.Commented:
>> I just thought if I create a plugin to do this, i could reuse this in future sites, maybe.

Yeah, but the problem is that this really becomes two separate questions and each one is pretty complex.  You want to know how to introduce and integrate new data into a wordpress site AND how to package that as a plugin.  You should probably explore each of these in separate threads or solve one then ask the other.

>> how do I connect the database to a table and add, etc.. I have a table with data, which I want to be displayed in seperate pages

So the basic action you will be using is the wpdb() function.  Consider the following:

$newdb = new wpdb($DB_USER, $DB_PASSWORD, $DB_NAME, $DB_HOST);
$mynewquery - $newdb->get_results( "SELECT * FROM mytable" );

Open in new window


That's all you need to initialize a connection to another database.  If your table is in the current WP database, it's even simpler:

$mynewquery = $wpdb->get_results( "SELECT * FROM mytable" );

Open in new window


No need to create a new connection.  From there, you use the ability of wpdb() to output results into HTML

http://codex.wordpress.org/Class_Reference/wpdb

For instance, to output the the get_results from above as a list:

echo "<ul>";
foreach ($mynewquery as $obj) :
   echo "<li>".$obj->ColumnName."</li>";
endforeach;
echo "</ul>";

Open in new window


So from here you could be building this into page templates or converting it to a function and then a WP shortcode, etc. etc.


0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
FeziAuthor Commented:
Thanks, solution was correct.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
WordPress

From novice to tech pro — start learning today.