<tfoot id='FTwu6'></tfoot>

<small id='FTwu6'></small><noframes id='FTwu6'>

    <i id='FTwu6'><tr id='FTwu6'><dt id='FTwu6'><q id='FTwu6'><span id='FTwu6'><b id='FTwu6'><form id='FTwu6'><ins id='FTwu6'></ins><ul id='FTwu6'></ul><sub id='FTwu6'></sub></form><legend id='FTwu6'></legend><bdo id='FTwu6'><pre id='FTwu6'><center id='FTwu6'></center></pre></bdo></b><th id='FTwu6'></th></span></q></dt></tr></i><div id='FTwu6'><tfoot id='FTwu6'></tfoot><dl id='FTwu6'><fieldset id='FTwu6'></fieldset></dl></div>

        <legend id='FTwu6'><style id='FTwu6'><dir id='FTwu6'><q id='FTwu6'></q></dir></style></legend>
          <bdo id='FTwu6'></bdo><ul id='FTwu6'></ul>

        将 PHP 浮点数/十进制值插入 MySQL

        Inserting PHP float/decimal values into MySQL(将 PHP 浮点数/十进制值插入 MySQL)
        • <i id='M1Umv'><tr id='M1Umv'><dt id='M1Umv'><q id='M1Umv'><span id='M1Umv'><b id='M1Umv'><form id='M1Umv'><ins id='M1Umv'></ins><ul id='M1Umv'></ul><sub id='M1Umv'></sub></form><legend id='M1Umv'></legend><bdo id='M1Umv'><pre id='M1Umv'><center id='M1Umv'></center></pre></bdo></b><th id='M1Umv'></th></span></q></dt></tr></i><div id='M1Umv'><tfoot id='M1Umv'></tfoot><dl id='M1Umv'><fieldset id='M1Umv'></fieldset></dl></div>

              <tbody id='M1Umv'></tbody>
            1. <tfoot id='M1Umv'></tfoot>

              • <bdo id='M1Umv'></bdo><ul id='M1Umv'></ul>

                  <legend id='M1Umv'><style id='M1Umv'><dir id='M1Umv'><q id='M1Umv'></q></dir></style></legend>

                  <small id='M1Umv'></small><noframes id='M1Umv'>

                  本文介绍了将 PHP 浮点数/十进制值插入 MySQL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  说实话,这是一个非常简单的问题.我一直在谷歌上寻找解决方案,但似乎没有任何效果.我的数据库中有以下字段:

                  It's a pretty simple question to be honest. I've been looking for a while now on Google for a solution but nothing seems to work. I have the following field in my database:

                  decimal(2,1)
                  

                  我在 PHP 中有两个变量(来自通过 POST 插入表单的值)我想将它们加在一起,然后插入到这个字段中.

                  I have two variables in PHP (which come from values inserted into a form via POST) I want to add together and then insert into this field.

                  $sql2 = $link->prepare("INSERT INTO league_stats (match_id, rating)
                  VALUES (?, ?)");
                  $sql->bind_param("ii", $match_id, $rating);
                  
                  $match_id = $_SESSION["match_id"];
                  $rtg1 = $_POST[$rating_1"];
                  $rtg2 = $_POST[$rating_2"] / 10;
                  $rating = $rtg1 + $rtg2;
                  

                  例如,rtg1 为 7,rtg2 为 3 除以 10,因此结果为 0.3.然后我将这两个数字相加得到 7.3.当我将它插入数据库时,它总是显示第二个数字为 0.所以它会显示为 7.0 而不是 7.3.我尝试了许多不同的方法,但总是得到完全相同的结果.

                  For example, rtg1 would be 7 and rtg2 would be 3 divided by 10 so it comes out as 0.3. I then add these two numbers together to make 7.3. When I go to insert it into the database, it always displays the second digit as 0. So instead of 7.3 it would come out as 7.0. I've tried many different methods but I always get the exact same result.

                  我什至将 $rating 分配给一个原始值,只是为了测试我的变量是否有问题:

                  I even assigned $rating to a raw value just to test if there was something wrong with my variables:

                  $rating = 7.5
                  

                  仍然是 7.0.

                  有人可以提供一个示例,说明如何将浮点类型的 PHP 变量正确插入 MySQL 吗?还可以解释如何正确地将两个浮点值加在一起?谢谢!

                  Could somebody please provide an example of how to correctly insert a float type PHP variable into MySQL? And also maybe explain how to correctly add two float values together? Thanks!

                  推荐答案

                  你告诉 php 将 $match_id$rating 转换为整数.你应该使用:

                  You are telling php to cast $match_id and $rating to integer. You should use:

                  $sql->bind_param("id", $match_id, $rating);
                  

                  而不是

                  $sql->bind_param("ii", ...
                  

                  这篇关于将 PHP 浮点数/十进制值插入 MySQL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  DeepL的翻译效果还是很强大的,如果我们要用php实现DeepL翻译调用,该怎么办呢?以下是代码示例,希望能够帮到需要的朋友。 在这里需要注意,这个DeepL的账户和api申请比较难,不支持中国大陆申请,需要拥有香港或者海外信用卡才行,没账号的话,目前某宝可以
                  PHP通过phpspreadsheet导入Excel日期,导入系统后,全部变为了4开头的几位数字,这是为什么呢?原因很简单,将Excel的时间设置问文本,我们就能看到该日期本来的数值,上图对应的数值为: 要怎么解决呢?进行数据转换就行,这里可以封装方法,或者用第三方的
                  mediatemple - can#39;t send email using codeigniter(mediatemple - 无法使用 codeigniter 发送电子邮件)
                  Laravel Gmail Configuration Error(Laravel Gmail 配置错误)
                  Problem with using PHPMailer for SMTP(将 PHPMailer 用于 SMTP 的问题)
                  Issue on how to setup SMTP using PHPMailer in GoDaddy server(关于如何在 GoDaddy 服务器中使用 PHPMailer 设置 SMTP 的问题)

                    <tfoot id='cOiIE'></tfoot>

                          <bdo id='cOiIE'></bdo><ul id='cOiIE'></ul>
                          <i id='cOiIE'><tr id='cOiIE'><dt id='cOiIE'><q id='cOiIE'><span id='cOiIE'><b id='cOiIE'><form id='cOiIE'><ins id='cOiIE'></ins><ul id='cOiIE'></ul><sub id='cOiIE'></sub></form><legend id='cOiIE'></legend><bdo id='cOiIE'><pre id='cOiIE'><center id='cOiIE'></center></pre></bdo></b><th id='cOiIE'></th></span></q></dt></tr></i><div id='cOiIE'><tfoot id='cOiIE'></tfoot><dl id='cOiIE'><fieldset id='cOiIE'></fieldset></dl></div>
                            <tbody id='cOiIE'></tbody>

                          <small id='cOiIE'></small><noframes id='cOiIE'>

                            <legend id='cOiIE'><style id='cOiIE'><dir id='cOiIE'><q id='cOiIE'></q></dir></style></legend>