Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Primary Key from 1 to 01, 2 to 02, etc

I have a primary key field (news_id) in the news table

it start from 1, 2, 3, 4 and so on..

However, I like to change to 01, 02, 03, 04,e tc ... is that possible?

If not, how can that be done in PHP?

like image 861
user622378 Avatar asked Dec 07 '22 20:12

user622378


1 Answers

Manipulating the keys directly is a bad idea in 99% of cases.

The best way to go is probably to change the format when outputting the keys like shown in this question:

$key = 4;
echo sprintf('%02d', $key); // outputs 04
like image 64
Pekka Avatar answered Dec 09 '22 09:12

Pekka