[resolved] Use DB For Special Purpose (11 posts)

  1. filias
    Posted 3 years ago #

    For my page, I need to get a number from a db.

    I then need to place the number in the page.

    I then need to update the db to add 1 to the db field, so the next time I retrieve a number from the db, it will be incremented.

    Questions: how do I set up the db from which I can retrieve the number?

    Once the db is set up, is there anything special about the php coding I will use?

    Do I use a plugin for the php coding?

    If so, which plugin?

  2. fonglh
    Posted 3 years ago #

    this isn't really a WordPress question, it's a MySQL and PHP question.

    you can setup a column in MySQL to increment when creating the table.

    Perhaps if you explained the actual task it might be possible to do it within WordPress instead.

  3. filias
    Posted 3 years ago #

    I can do this in a non wordpress site. In fact, I could have wp open my present php page in a new window, but I prefer to have this all within wp.

    Explanation: I have an online ticket for an association fund raiser. The first ticket each year begins with the number 1. When a user goes to my ticket page, she sees the number 1. The next user to go to the page sees the number two. On and on.

    I'm looking for something very basic to get started. How do I create a table in the wp MySQL db? I know how to do this using MySQL (non-wp). I would just go into MySQL and create a new table. Then I would code the php into my php page.

    Do I start by going into the wp MySQL db and making a new table there?

  4. fonglh
    Posted 3 years ago #

    Perhaps you can consider using post_meta instead? Take a look at the following tutorial to see how it's used to keep track of page views.


  5. filias
    Posted 3 years ago #

    I took a look at that, and I'll come back to it.

    When I read your post, it prompted me to search in a different way. I found an article that says:
    "In 99% of the currently available WordPress plugins, there is absolutely no need for them to have a custom table – WordPress utilizes the ‘options’ table to help in most cases. However, what if your plugin requires it’s own “space” in the WordPress database?" (http://wptoy.com/tips-tricks/create-a-plugin-with-its-own-custom-database-table/)

    Do you know how to access the options table? Or, perhaps that wouldn't fit with what I'm trying to do?

  6. fonglh
    Posted 3 years ago #


    and similar functions for update and delete.

    These functions are usually used to store plugin settings, but you could use them to store anything else.

    It basically adds entries to the wp_options table.

  7. filias
    Posted 3 years ago #

    I'd like to give this a try first.

    Sounds like I need to go into wp-includes/functions.php and put the following in:

    <?php add_option( 'ticket_count', '1', '', 'yes' ); ?>

    Although, since I am going to be calling the number with my php code, I may want "no" instead of "yes".

  8. fonglh
    Posted 3 years ago #

    No, you should not edit core files or you'll lose the changes on the next update.

    Create a plugin and add the option when the plugin is activated.

  9. filias
    Posted 3 years ago #

    Much to my surprise, I've found that within my wp page I can retrieve the information I need from my non-wp db that I've been using all along for my non-wp page (I'm changing my site to wp from my traditional XHTML coded site).

    I'm using the plugin Exec-PHP for the PHP code and the MySQL code, and everything is working perfectly.

    Is there any reason I shouldn't use my non-wp db? I do have a limit on the number of db's I can use, but I'm not near that limit.

  10. fonglh
    Posted 3 years ago #

    Not that I can think of. If that works for you then it's fine, glad you got it sorted out :)

  11. filias
    Posted 3 years ago #

    Thank you. I'll go with that then, at least until I can learn more about using the wp db method you suggested.

    Thank you for your help. One thing led to another after I started talking to you, and that finally led to a solution.

Topic Closed

This topic has been closed to new replies.

About this Topic