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 8476587
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T18:13:15+00:00 2026-06-10T18:13:15+00:00

I wrote a code that lets the user vote for one out of the

  • 0

I wrote a code that lets the user vote for one out of the two options and the score is calculated using a modified Elo rating system. However, digits to the right of the decimal point are ignored when I vote for either of the options. I added the floatval function but it didn’t help.

$query = "SELECT pic,score,id FROM nfl
    JOIN (SELECT r1.random_id
         FROM nfl_map AS r1
         JOIN (SELECT (RAND() *
                      (SELECT MAX(row_id)
                         FROM nfl_map)) AS row_id)
               AS r2
        WHERE r1.row_id >= r2.row_id
        ORDER BY r1.row_id ASC
        LIMIT 1) as rows ON (id = random_id)";

    $query_2 = "SELECT pic,score,id FROM nfl
    JOIN (SELECT r1.random_id
         FROM nfl_map AS r1
         JOIN (SELECT (RAND() *
                      (SELECT MAX(row_id)
                         FROM nfl_map)) AS row_id)
               AS r2
        WHERE r1.row_id >= r2.row_id
        ORDER BY r1.row_id ASC
        LIMIT 1) as rows ON (id = random_id)";
    $res_2 = $mysqli->query($query_2);
    if (!$res_2) die ("Result display failed: " . $mysqli->errno . " - " . $mysqli->error);
    $pic_2 = $res_2->fetch_assoc();
    $id_2 = $res_2->fetch_assoc();
    $score_2 = $res_2->fetch_assoc();


    $res_1 = $mysqli->query($query);
    if (!$res_1) die ("Result display failed: " . $mysqli->errno . " - " . $mysqli->error);
    $pic_1 = $res_1->fetch_assoc();
    $id_1 = $res_1->fetch_assoc();
    $score_1 = $res_1->fetch_assoc();
    $Ra = $score_1;
    $Rb = $score_2;
    $calc_pow_1 = (($Rb - $Ra) / 400);
    $calc_pow_2 = (($Ra - $Rb) / 400);
    $float_calc_pow_1 = floatval($calc_pow_1);
    $float_calc_pow_2 = floatval($calc_pow_2);
    $Ea = 1 / (1 + pow(10,$float_calc_pow_1));
    $Eb = 1 / (1 + pow(10,$float_calc_pow_2));
    $float_Ea = floatval($Ea);
    $float_Eb = floatval($Eb);

    // if user votes for picture no. 1
    if (isset($_POST['vote_1']) && isset($_POST['id']) && isset($_POST['score']))
    {
    $id = $_POST['id'];
    /* $score = $_POST['score'];
    $pic = $_POST['pic']; */
    //$mod = 2 * $Eb;
    $K = 4;
    $float_mod_1 = floatval($K * (1 - $float_Ea));

    $query = "UPDATE nfl SET score=?+$float_mod_1 WHERE id=?";
    // $score_new = $_POST['score'] + $mod;
    $score_new = $_POST['score'] + $float_mod_1;

    $stmt = $mysqli->prepare($query);
    $stmt->bind_param('di', $_POST['score'], $_POST['id']);
    $stmt->execute();
    if ($stmt->errno) {
        echo "Vote failed: " . $stmt->error();
    }
    else echo "Vote succeeded! New score of $id_1 is $score_new!

"; $stmt->close(); } // fetch picture no. 2 // // query to the database /* $query_2 = "SELECT pic,score,id FROM nfl JOIN (SELECT r1.random_id FROM nfl_map AS r1 JOIN (SELECT (RAND() * (SELECT MAX(row_id) FROM nfl_map)) AS row_id) AS r2 WHERE r1.row_id >= r2.row_id ORDER BY r1.row_id ASC LIMIT 1) as rows ON (id = random_id)"; $res_2 = $mysqli->query($query_2); if (!$res_2) die ("Result display failed: " . $mysqli->errno . " - " . $mysqli->error); $pic_2 = $res_2->fetch_assoc(); $id_2 = $res_2->fetch_assoc(); $score_2 = $res_2->fetch_assoc(); */ // if user votes for picture no. 2 if (isset($_POST['vote_2']) && isset($_POST['id']) && isset($_POST['score'])) { $id = $_POST['id']; /* $score = $_POST['score']; $pic = $_POST['pic']; */ //$mod = 2 * $Ea; $K = 4; $float_mod_2 = floatval($K * (1 - $float_Eb)); $query = "UPDATE nfl SET score=?+$float_mod_2 WHERE id=?"; // $score_new = $_POST['score'] + $mod; $score_new = $_POST['score'] + $float_mod_2; /* $query = "UPDATE nfl SET score=?+1 WHERE id=?"; $score_new = $_POST['score'] + $mod; */ $stmt = $mysqli->prepare($query); $stmt->bind_param('di', $_POST['score'], $_POST['id']); $stmt->execute(); if ($stmt->errno) { echo "Vote failed: " . $stmt->error(); } else echo "Vote succeeded! New score of $id_2 is $score_new!

"; $stmt->close(); }

Here is the full code, if you need to see it: http://snipt.org/vDhj2

The code handling the situation when the user votes for the second option is pretty much the same (except $Ea changes to $Eb etc.). The ‘score’ row’s properties in MySQL are following:

float(8,3) not null

Thanks.

EDIT: I’m not getting the notice anymore.

  • 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-10T18:13:16+00:00Added an answer on June 10, 2026 at 6:13 pm

    I think you simply missed a declaration in your code:

    $res_1 = $mysqli->query($query);
    if (!$res_1) die ("Result display failed: " . $mysqli->errno . " - " . $mysqli->error);
    $pic_1 = $res_1->fetch_assoc();
    $id_1 = $res_1->fetch_assoc();
    $score_1 = $res_1->fetch_assoc();
    $Ra = $score_1;
    $Rb = $score_2;
    

    I cannot see $score_2 defined anywhere in the code above where you try to assign it’s value to another variable.

    Warnings are there for a reason – ignoring them is a bad idea as it will inevitably lead to an error in your code. in this case, you simply need to declare your variable before you assign it (even if it is si,ply $score_2=0; if that is to be the default value, but assign it nonetheless.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to write a simple app that lets a user grant my code
I recently wrote code that didnt work as i would expect, it was: message
I wrote some code that activity starts a service to get some text from
I wrote this code that compiles on Solaris gcc it works fine too for
So, here's the problem. I wrote a code that opens a div based on
Years ago, I wrote a code template that took a few simple parameters (points)
I wrote some code in VHDL that is expected to look at a rotory
I wrote this piece of code that is supposed to redirect something written on
I have some python code that I wrote to convert a python list into
I was thinking about a code that I wrote a few years ago in

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.