leeming Posted July 6, 2006 Share Posted July 6, 2006 ok in my databse field, 0 is an option. and since int doesnt save 0, and have to use varchar instead...this is my problem...im wanting to order the table by this field, but some thing like the following outputs[quote]1101123355[/quote]instead of the ovious...is there a command when selecting the field, to like[code]"SELECT table.field AS table.field(INT) [/code] Link to comment https://forums.phpfreaks.com/topic/13862-order-by-order-varchar-interger-data-0-fields-like-int/ Share on other sites More sharing options...
Wildbug Posted July 6, 2006 Share Posted July 6, 2006 See the [url=http://dev.mysql.com/doc/refman/5.1/en/cast-functions.html]cast functions[/url]. I haven't tried it, but something like "SELECT CAST(table.field AS UNSIGNED) AS IntColumn ... ORDER BY IntColumn" might work.And what do you mean by "int doesnt save 0"? You can have a zero in an integer column. If you need to differentiate between "no value" and "zero," use NULL. Link to comment https://forums.phpfreaks.com/topic/13862-order-by-order-varchar-interger-data-0-fields-like-int/#findComment-53981 Share on other sites More sharing options...
leeming Posted July 6, 2006 Author Share Posted July 6, 2006 ok thanks, i did come across the CAST function slightly after i posted this... but i just didnt understand it...as for the '0' in INT, i didnt know that.. always been told to us it as varchar Link to comment https://forums.phpfreaks.com/topic/13862-order-by-order-varchar-interger-data-0-fields-like-int/#findComment-53985 Share on other sites More sharing options...
fenway Posted July 6, 2006 Share Posted July 6, 2006 Besides, why are you storing numbers in a varchar field? And "+0" works wonders too, and doesn't require 4+. Link to comment https://forums.phpfreaks.com/topic/13862-order-by-order-varchar-interger-data-0-fields-like-int/#findComment-54000 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.