• Whenever a user hops on a page on my wordpress site I would like that user to be able to click 8 or so different buttons. When they click one of these buttons I would like to store it with their user profile so that the Admin and the user can see that they’ve done so. Each of these buttons will write a different value to the database. Essentially its “attached” to their user profile. I’d like to keep track of how many of these buttons they’ve clicked and how many different pages they’ve interacted with.

    Is this possible? If not, would it be best to create a separate SQL database or tie into wordpress’ database (keep in mind I feel this is going to carry ALOT of data, but simple data).

    Feel free to ask additional questions if i’m not being clear enough.

Viewing 6 replies - 1 through 6 (of 6 total)
  • It’s going to be pretty easy to do. I’d suggest uisng AJAX to record everything becaue you’ll keep the users on your pages, and it’s a lot more user-friendly for things like that.

    As far as where ot store it, I’d use a new table in the existing database. MySQL is pretty good at data storage, and can hold a whole heap of records without a problem. The biggest single table that I’ve worked with so far was around 8GB, and the only downside to that was trying to search on non-indexed fields, but when the indexing was there it was still pretty fast.

    Thread Starter cerics

    (@cerics)

    Thank you for your response. Pretty much what I want to do is make a html bullet input selector that exists on every page. The user can select one of those options and the value is sent to the database.

    Do you have any further input?

    Also, would it be best to write to the database via php, are there any plugins that would accomplish all of this?

    I don’t know what other input that you’d need. It can be doen and is pretty simple to do with a custom-written plugin with two or three functions. There might be some existing plugins that can help with this, but I haven’t needed this sort of thing before (and if I did I’m much more likely to write it myself so I know it works the way that I want it to).

    You will need to use PHP to write to the database. Using AJAX is only to send the values from the client to the server, so your AJAX function would call the remote URL on the server, and the PHP on the server woudl do the processing. You can see more about it here.

    Thread Starter cerics

    (@cerics)

    Ok so I’ve successfully built some php that will write a row to a custom database. Any idea how I can tie this to a button action?

    <?php
    global $wpdb;

    // Get URL
    $Path=$_SERVER[‘REQUEST_URI’];
    $URI=’https://www.example.com&#8217;.$Path;

    // Get Current User
    $user = wp_get_current_user();

    // Inject row into custom_table
    $wpdb->insert(
    ‘custom_table’,
    array(
    ‘user’ => $user->user_login,
    ‘page’ => $URI,
    ‘vote’ => 6,
    ‘date’ => current_time(‘mysql’)),
    array(
    ‘%s’,
    ‘%s’,
    ‘%d’,
    ‘%s’
    )
    );
    ?>

    Look at the link that I posted before. That’s the info that you’ll need on using AJAX to do make the action happen.

    Thread Starter cerics

    (@cerics)

    OK thank you I will try this and let you know. This is my first time working with AJAX. I appreciate your advice!

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Writing custom data to an additional mySQL database’ is closed to new replies.