PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Wednesday, January 26, 2022

[FIXED] How can last row if last row is 003

 January 26, 2022     eloquent, laravel, laravel-5     No comments   

Issue

how do I add +1 data if the last data type varchar data is in format 001, 002, 003 , i try that but results is 1

 $nis = Profile::all()->last();
        $nisnow = $nis->nis += 1;
        dd($nisnow);

Edited : my expect results if last data 003 + 1=004


Solution

PHP will change string to integer when you calculate, so you can use str_pad to change the integer to string and fill with '0', it will keep the string with three numbers.

$nisnow = $nis->profile += 1;
str_pad($nisnow, 3, '0', STR_PAD_LEFT);


Answered By - TsaiKoga
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing