【问题标题】:Change a number corresponding to change in another number改变一个数字对应于另一个数字的改变
【发布时间】:2021-10-05 06:48:11
【问题描述】:

假设我有 6 个要保存到 mysql 的数据条目,我有 4 个条目作为条目 A,其中一个 billNo(例如:3) 和另外两个带有另一个 BillNo。即,(条目 A:Billno = 3,条目 B:Billno = 5)。

我想要的是billno更改对应于sql, -max(billno) 在 mysql 中是 15。

  • 我想将条目 A 的 billno 从 3 更改为 16(sql+1 中的 max(billno))和
  • 条目 B 至 17 条目 C、D 也是如此......

我已经给出了一些 php 代码来演示它

public function saveIntransactionOne() {
        if ($_SERVER['REQUEST_METHOD'] === 'POST') {
            if (isset($_POST["salesIntransItems"]) and isset($_POST["intranscount"])) {
                $json = $_POST["salesIntransItems"];
                $json1 = $_POST["intranscount"];
                $BillNo = $this->model_mobileapi->getInvNoIntrans();
               if (get_magic_quotes_gpc()) {
                   $json = stripslashes($json);
               }
                $data = json_decode($json);
                $a = array();
                $b = array();
                $newBill =  $data[$j]->inv_no;
                  
                if ($_POST['code'] == 1) {
                for ($i = 0; $i < count($data); $i++) {
                    $res = $this->model_mobileapi->saveintrans($data[$i]->itemname, $data[$i]->qty, $data[$i]->rate, $data[$i]->total, $data[$i]->party, $data[$i]->net_qty,$data[$i]->net_amnt,$data[$i]->godown, $data[$i]->employee, $data[$i]->date1, $newBill, $data[$i]->local_app_user_entry_id,$data[$i]->credit,$data[$i]->inv_no_str,$data[$i]->type);
                        $b["id"] = $data[$i]->local_app_user_entry_id;
                        $b["party"] = $data[$i]->party;
                        $b["status"] = 'uploaded';
                        array_push($a, $b);
                }
                echo json_encode($a);
                }
            }
            }else {
                $response["success"] = 0;
                $response["message"] = "Required field(s) is missing";
                echo json_encode($response);
            }
        } else {
            $response["success"] = 0;
            $response["message"] = "Something went wrong";
            echo json_encode($response);
        }

-> $BillNo = $this->model_mobileapi->getInvNoIntrans(); 是 mysql max(billno)

-> $newBill = $data[$j]->inv_no; 是传入的条目帐单

希望你能理解我的问题,我会提供任何关于这个问题的答案。

谢谢

【问题讨论】:

  • 为什么把它标记为java?
  • 对不起,我拿了一个随机标签。

标签: php mysql codeigniter numbers logic


【解决方案1】:

不过,我得到了答案。有点棘手,但效果很好!

 public function saveIntransactionOne() {
        if ($_SERVER['REQUEST_METHOD'] === 'POST') {
            if (isset($_POST["salesIntransItems"]) and isset($_POST["intranscount"])) {
                $json = $_POST["salesIntransItems"];
                $json1 = $_POST["intranscount"];
               if (get_magic_quotes_gpc()) {
                   $json = stripslashes($json);
                   $json1 = stripslashes($json1);
               }
                $data2 = json_decode($json,true);
                $data = json_decode($json);
                $data1 = json_decode($json1,true);
                // echo json_encode($data1);
                $a = array();
                $b = array();
                for( $z = 0; $z < count($data1) ; $z++){
                $BillNo = $this->model_mobileapi->getInvNoIntrans();
                if ($_POST['code'] == 1) {
                for ($i = 0; $i < count($data); $i++) {
                    if ( $data2[$i]["inv_no"] != $data1[$z]["inv_no"]) {
                        continue;
                    } else {
                    $res = $this->model_mobileapi->saveintrans($data[$i]->itemname, $data[$i]->qty, $data[$i]->rate, $data[$i]->total, $data[$i]->party, $data[$i]->net_qty,$data[$i]->net_amnt,$data[$i]->godown, $data[$i]->employee, $data[$i]->date1, $BillNo, $data[$i]->local_app_user_entry_id,$data[$i]->credit,$data[$i]->inv_no_str,$data[$i]->type);
                        $b["id"] = $data[$i]->local_app_user_entry_id;
                        $b["party"] = $data[$i]->party;
                        $b["status"] = 'uploaded';
                        array_push($a, $b);
                }
            }
                echo json_encode($a);
            }
            }
            }else {
                $response["success"] = 0;
                $response["message"] = "Required field(s) is missing";
                echo json_encode($response);
            }
        } else {
            $response["success"] = 0;
            $response["message"] = "Something went wrong";
            echo json_encode($response);
        }
    }

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-05-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-03-21
    • 2011-02-19
    • 2021-09-03
    • 1970-01-01
    相关资源
    最近更新 更多