Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8023289
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T22:31:27+00:00 2026-06-04T22:31:27+00:00

I have some plugin code that is supposed to look up the number of

  • 0

I have some plugin code that is supposed to look up the number of “up_votes” in the database, and if an input has been clicked, add another “up” vote to the database using an UPDATE query.

The problem is, it only works once. I can click on the input, and update the value from 0 to 2, but can’t go to 3, 4, 5, etc. when the page reloads. Obviously, something is going wrong.

Here’s the code with comments marked “problem” where I’m running into trouble:

/*
DISPLAY THE LIST
*/          
//Get the list from the database, and set the variables for display in the output.
$get_list = $wpdb->get_results('SELECT entry_ID, '.$cb_lud_field1_name.' AS "field1", '.$cb_lud_field2_name.' AS "field2", up_votes, down_votes, up_votes - down_votes AS "total_votes"
    FROM '.$cb_lud_table.'
    GROUP BY entry_ID
    ORDER BY total_votes DESC
    ',OBJECT);

//Check if list is null, and if so, set a variable to display a warning. Otherwise, display the list.
if (empty($get_list)) {
    $cb_lud_sc_output .= "<em>Warning: You don't seem to have any records for this list. Why don't you add some now?</em>";
    $cb_lud_sc_output .= $cb_lud_sc_form;
    return $cb_lud_sc_output;
}
else {
    $cb_lud_sc_output .= $cb_lud_sc_form;
    $cb_lud_sc_output .= '</br>';
    $cb_lud_sc_output .= '<table border="1" cellpadding="10">';
    $cb_lud_sc_output .= '<tr><td align="center"><strong>'.$cb_lud_field1_name.'</strong></td><td align="center"><strong>'.$cb_lud_field2_name.'</strong></td><td align="center"><strong>Score</strong></td><td align="center"><strong>Vote Up/Down</strong></td></tr>';
        foreach ($get_list as $list_items) {
            $cb_lud_sc_output .= '<tr><td>'.stripslashes($list_items->field1).'</td><td>'.stripslashes($list_items->field2).'</td><td>'.$list_items->total_votes.'</td><td><form action="" method="post"><input name="arrow-up-ID-'.$list_items->entry_ID.'" type="image" src="'.$cb_lud_upimg.'" value="'.$list_items->entry_ID.'"/>&nbsp;<input name="arrow-down-ID-'.$list_items->entry_ID.'" type="image" src="'.$cb_lud_downimg.'" value="'.$list_items->entry_ID.'"/></form></td></tr>';
        }
    $cb_lud_sc_output .= '</table>';
    //Problem --> Seems like I've set a variable for the current_up_votes, added it to 1, so if there are currently 2 up_votes, it should go to 3, but it stops at 2 for some reason.
    //find the values posted to the form
    $cb_lud_arrow_keys = array_keys($_POST);
    $cb_lud_arrow_values = array_values($_POST);
    $cb_lud_entry_id = (int)$cb_lud_arrow_values[2];
    $cb_lud_current_up_votes = $wpdb->query('SELECT up_votes
        FROM '.$cb_lud_table.' 
        WHERE entry_ID = '.$cb_lud_entry_id.'', ARRAY_A);
    $i = 1;
    $cb_lud_new_up_votes = $cb_lud_current_up_votes + $i;
    var_dump($cb_lud_current_up_votes);
    var_dump($cb_lud_base_votes);
    var_dump($cb_lud_new_up_votes);

        //set some variables to "up" or "down" depending on form input.
            if (strpos($cb_lud_arrow_keys[2], 'up-ID') > 0) {
                $cb_lud_arrow_direction = "up";
            }
            else if (strpos($cb_lud_arrow_keys[2], 'down-ID') > 0) {
                $cb_lud_arrow_direction = "down";
            }
            else {
                $cb_lud_arrow_direction = "nothing";
            }

        //create the update query that will record the up and down votes.
            if ($cb_lud_arrow_direction == "up" && $cb_lud_arrow_direction != "nothing") {
                $wpdb->query('UPDATE '.$cb_lud_table.' SET up_votes='.$cb_lud_new_up_votes.'
                    WHERE entry_ID='.$cb_lud_entry_id.'');
            }
            else if ($cb_lud_arrow_direction == "down" && $cb_lud_arrow_direction != "nothing") {
                //Get the id and update it to the down field
            }

    return $cb_lud_sc_output;
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T22:31:28+00:00Added an answer on June 4, 2026 at 10:31 pm

    To test the increment try changing your UPDATE query to:

    $wpdb->query('UPDATE '.$cb_lud_table.' SET up_votes=up_votes+1
                    WHERE entry_ID='.$cb_lud_entry_id.'');
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Does jQuery validation plugin have some dependencies? For example, I saw blogposts that said
I have some photos that are split on successive pages through will_paginate plugin. When
I have a plugin that is loaded by this application.. This plugin calls some
I have a ckeditor plugin that depends on some custom parameters. These parameters may
I have a html-table, that has a header, that is supposed to be clickable
Suppose i have a main js file on the website that contains some code
I have some code that that I only want to execute if curl_init() is
I have just optimised some Ruby code that was in a controller method, replacing
We have some code that must access low level windows XP os calls which
I have some server code that is generating thumbnails when an image is uploaded.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.