简体   繁体   中英

the condition of if and else are false and its jump to else directly and my data are true

        $reqAmount = $service->price;
        $useraa = auth()->user();
        //$usersRl = DB::table('gift_card_services')->select('id')->get();
        $usersDay1 = DB::table('gift_card_services')->select('created_at')->where('id',1)->get();
        $usersDay4 = DB::table('gift_card_services')->select('created_at')->where('id',4)->get();
        $usersDay7 = DB::table('gift_card_services')->select('created_at')->where('id',7)->get();
        if ($useraa->username == "abdoumadris") {
            // $reqAmount = ($service->price - 2);
            if ($usersDay1 == "2022-10-07 19:56:20" ) {
                $reqAmount = ($service->price - 2);
            }
            else if ($usersDay4 == "2022-10-07 19:57:20") {
                $reqAmount = ($service->price - 6);
            }
            else if ($usersDay7 == "2022-10-07 19:59:00") {
                $reqAmount = ($service->price - 10);
            }else{
                $reqAmount = ($service->price - 1);
            }
        }

i need to change the price for all product but its allways - 1

i am sure 100% that my data are set correctly and the if condition is true, but it's override to else directly

It is a bit tricky to work with date/time. What you are comparing is a special string representation of format 'Ymd H:i:s'. You should check if these dates are really also stored like that in the database. This is not the way I would expect date/time to be stored.

Please give a dump of $usersDay1, $usersDay4 and $usersDay7. If these are timestamps, you might need to bring them to a different format before comparing them to string representations.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM