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 Quote Link to comment Share on other sites More sharing options...
pouncer Posted April 8, 2007 Author Share Posted April 8, 2007 any ideas guys? Quote Link to comment 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"; Quote Link to comment 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? Quote Link to comment 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 Quote Link to comment 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 Quote Link to comment 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) Quote Link to comment 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 Quote Link to comment 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`"); Quote Link to comment 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. Quote Link to comment Share on other sites More sharing options...
pouncer Posted April 8, 2007 Author Share Posted April 8, 2007 hey mate, are the `` needed? Quote Link to comment 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"); Quote Link to comment 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 ) Quote Link to comment 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) Quote Link to comment 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.