WordPress.org

Ready to get started?Download WordPress

Forums

$wpdb question... (1 post)

  1. WWDay3
    Member
    Posted 3 years ago #

    Does $wpdb need to be reset or unset somehow after a query is run?

    I hacked an existing plugin to include a rating/voting routine. The original plugin, using $wpdb, creates a list. I added icons that can be clicked on to vote the row up or down. My function was set up to execute an update query that did this:

    update xxx set votes = votes + 1 where xxx

    and vice-versa. It would do this, if necessary, right before reloading the file.

    The odd thing is that the votes would sometimes increment by 1, 2, or even 3.

    I debugged it by doing a get_var prior to the "voting" query executed and echoed the current vote total prior to updating the file. I would get a current vote number of 8, yet once the file was reloaded, it would have a vote value of 10. (And no, *I* was not executing the query more than once - I even unset the $_post variable that was passed to the function after the vote query ran just to make sure).

    It acted like WP was re-executing my query when the "next" query was run. Hence my question: does $wpdb have to be unset somehow?

    Currently I have it fixed by retrieving the vote into a variable, incrementing it in the script, and then updating the file using that variable.

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags