pouncer Posted April 8, 2007 Share Posted April 8, 2007 say my table has these 2 field: name address i want to change the field names to jpName jpAddress what would my alter query become in php guys? im a bit stuck Link to comment https://forums.phpfreaks.com/topic/46184-alter-query-confused/ Share on other sites More sharing options...
pouncer Posted April 8, 2007 Author Share Posted April 8, 2007 any ideas guys? Link to comment https://forums.phpfreaks.com/topic/46184-alter-query-confused/#findComment-224514 Share on other sites More sharing options...
jscix Posted April 8, 2007 Share Posted April 8, 2007 $change = "ALTER TABLE `tablename` CHANGE `name` `jpname` TYPE(LENGTH) NOT NULL"; Link to comment https://forums.phpfreaks.com/topic/46184-alter-query-confused/#findComment-224517 Share on other sites More sharing options...
pouncer Posted April 8, 2007 Author Share Posted April 8, 2007 thanks alot bud. TYPE(LENGTH) whats that mean? and also, cant i change both fieldnames in 1 line? r i have to have seperate queries? Link to comment https://forums.phpfreaks.com/topic/46184-alter-query-confused/#findComment-224518 Share on other sites More sharing options...
jscix Posted April 8, 2007 Share Posted April 8, 2007 ALTER TABLE `TABLE` CHANGE `name` `jpName` VARCHAR( 100 ) NOT NULL , CHANGE `address` `dpAddress` VARCHAR( 100 ) NOT NULL Link to comment https://forums.phpfreaks.com/topic/46184-alter-query-confused/#findComment-224519 Share on other sites More sharing options...
jscix Posted April 8, 2007 Share Posted April 8, 2007 sorry spelled it dpAddress instead of jp, but yeah. np Link to comment https://forums.phpfreaks.com/topic/46184-alter-query-confused/#findComment-224521 Share on other sites More sharing options...
pouncer Posted April 8, 2007 Author Share Posted April 8, 2007 do i have to have all that varchar NOT NULL stuff in, because thats already done when i created the fields beforehand. just want to change fieldnames (nothing else) Link to comment https://forums.phpfreaks.com/topic/46184-alter-query-confused/#findComment-224522 Share on other sites More sharing options...
jscix Posted April 8, 2007 Share Posted April 8, 2007 no, you dont need it. was just explaining what i meant by type/length Link to comment https://forums.phpfreaks.com/topic/46184-alter-query-confused/#findComment-224525 Share on other sites More sharing options...
pouncer Posted April 8, 2007 Author Share Posted April 8, 2007 thanks bud. so is this looking ok mysql_query("ALTER TABLE `TABLE` CHANGE `name` `jpName`, CHANGE `address` `dpAddress`"); Link to comment https://forums.phpfreaks.com/topic/46184-alter-query-confused/#findComment-224529 Share on other sites More sharing options...
jscix Posted April 8, 2007 Share Posted April 8, 2007 Yes, except `Table` should be the name of your table. Link to comment https://forums.phpfreaks.com/topic/46184-alter-query-confused/#findComment-224531 Share on other sites More sharing options...
pouncer Posted April 8, 2007 Author Share Posted April 8, 2007 hey mate, are the `` needed? Link to comment https://forums.phpfreaks.com/topic/46184-alter-query-confused/#findComment-224544 Share on other sites More sharing options...
pouncer Posted April 8, 2007 Author Share Posted April 8, 2007 it's not working bud. echo "ALTER TABLE `$cat` " . $data; $c = mysql_query("ALTER TABLE `$cat` " . $data); the echo gives me: ALTER TABLE `movies` CHANGE `title` `title` , CHANGE `media` `media` , CHANGE `director` `directorsssss` , CHANGE `cast` `cast` , CHANGE `description` `description` ..but it's not changing the director field name to directorsssss even this didn't work mysql_query("ALTER TABLE movies CHANGE director hello"); Link to comment https://forums.phpfreaks.com/topic/46184-alter-query-confused/#findComment-224546 Share on other sites More sharing options...
jscix Posted April 8, 2007 Share Posted April 8, 2007 See if this query works, $change = mysql_query("ALTER TABLE `movies` CHANGE `directors` `directorrrsss` VARCHAR( 100 ) NOT NULL"); If this doesnt work, I would just install phpMyAdmin ( Anytime you perform a command using their visual interface, it gives you the SQL Code, and has an option to output php formated code to use in your scripts ) Link to comment https://forums.phpfreaks.com/topic/46184-alter-query-confused/#findComment-224557 Share on other sites More sharing options...
pouncer Posted April 8, 2007 Author Share Posted April 8, 2007 ok this worked: mysql_query("ALTER TABLE `movies` CHANGE `directors` `hello` TEXT NOT NULL"); but how can i get the type of the fieldname? becasue what if the field name is int, etc.. (the page im making is for admins to edit field names) Link to comment https://forums.phpfreaks.com/topic/46184-alter-query-confused/#findComment-224562 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.