Topshed Posted August 12, 2009 Share Posted August 12, 2009 I am none to good with mysql so here goes I have an Char field length 5 , which I need to convert to an Integer . Just changing the type does not work as the code does not recognise a number from that field unless I go into edit mode and save the record again which fixes it. My question is is there a Replace command or similar to change the Field type CONTENT from char to integer, or perhaps Creating another field and copying the ex text field into the new field to make that field an interger . My thinking is I then delete the original field and rename the replacement to the original ??? I do hope that someone with the expertise can help, Regards Roy... Quote Link to comment https://forums.phpfreaks.com/topic/169921-problem-changing-a-fiels-from-char-to-int/ Share on other sites More sharing options...
PFMaBiSmAd Posted August 12, 2009 Share Posted August 12, 2009 The people who have altered a column to be an INT type generally don't have any problem. Perhaps you have something like leading spaces or leading zeros in the existing data. To manually do this, backup your database (in case anything goes wrong.) Add a new column of type INT. Execute a single UPDATE query (without a WHERE clause so it will operate on all rows in the table) to set the new column from the existing column values. Confirm your data works. Delete the old column. UPDATE your_table SET new_column = old_column Quote Link to comment https://forums.phpfreaks.com/topic/169921-problem-changing-a-fiels-from-char-to-int/#findComment-896486 Share on other sites More sharing options...
Topshed Posted August 13, 2009 Author Share Posted August 13, 2009 Thank you for the reply, You were correct, there was nothing wrong with my table, the problem was in the documentation. Working from a pdf document I found ’column_name1’ ,"", ’column_name2’ rather than 'column_name1',"",'column_name2' I cannot exactly reproduce the pdf single quote on my keyboard but the php code did not throw any errors just did not find the data ?? Very strange Regards Roy Quote Link to comment https://forums.phpfreaks.com/topic/169921-problem-changing-a-fiels-from-char-to-int/#findComment-896936 Share on other sites More sharing options...
fenway Posted August 21, 2009 Share Posted August 21, 2009 Those are backticks. Quote Link to comment https://forums.phpfreaks.com/topic/169921-problem-changing-a-fiels-from-char-to-int/#findComment-903178 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.