Jump to content

Archived

This topic is now archived and is closed to further replies.

wompus

modify a field throughout a table

Recommended Posts

I just started learning mysql today so this might sound stupid.

I have a field in a table called id. I would like to add a the number 0 before

each value in this field. How can i do this throughout the whole table?

Thanks

Share this post


Link to post
Share on other sites

One way would be to concatenate \"0\" to the id whenever u insert the data

 

like

 

say u have like this

 

eg $id has 100

 

$id = \'0\'.$id;

 

echo $id ;

 

this will display 0100

Share this post


Link to post
Share on other sites

OK. I use this field to sort entries in an online journal. I was fine till i hit 100 entries. Now when I sort in descending order, entry #100 ends up with entry #10. If I could put an extra zero infront of every entry number currently in the table it will fix this. I have no problem entering data into this table in the correct format. My question is, can I add the number 0 before every value in a specified column or do i have to edit each one using phpmyadmin.

Share this post


Link to post
Share on other sites

Nevermind. I got it. I changed the type of field to an integer. Now it sorts correctly without 0s infront of numbers.

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.