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?
 
Jason C. LevineConnect With a Mentor No oneCommented:
>> 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
 
FeziAuthor Commented:
Hi Experts,

Can anyone shed some light on this topic, please? I've not found a solution for this.
0
 
Jason C. LevineNo oneCommented:
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
 
FeziAuthor Commented:
Thanks, solution was correct.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.