phpocean Posted May 7, 2009 Share Posted May 7, 2009 Ok I i have a table in my MySQL with existing fields. I decided to add another field and wanted to use INSERT INTO to put data into that field. My auto_increment id is currently at 80. Supposedly I wanted to put data into my newly added field starting from id 1. How would I write the code to put data into the field starting from id 1? I am able to put data into my newly added field, but it will not start adding data from id 1, but id 81, which is not what I wanted. Any help would be much appreciated. Quote Link to comment https://forums.phpfreaks.com/topic/157162-solved-mysql-insert-into-issue/ Share on other sites More sharing options...
Ken2k7 Posted May 7, 2009 Share Posted May 7, 2009 If the table is empty, then you can easily do that by running TRUNCATE on it. If not, then why would it matter? Also, wrong forum dude. Quote Link to comment https://forums.phpfreaks.com/topic/157162-solved-mysql-insert-into-issue/#findComment-828137 Share on other sites More sharing options...
phpocean Posted May 7, 2009 Author Share Posted May 7, 2009 ummm what do you mean wrong forum? FYI I'ma woman. How do I use TRUNCATE? Here is my INSERT TO code: CREATE TABLE `pho_pic` ( `Article` int(11) NOT NULL auto_increment, `thumb` varchar(100) NOT NULL default '', PRIMARY KEY (`Article`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=81 ; -- -- Dumping data for table `pho_pic` -- INSERT INTO `ocean_pictures` (`id`, `thumbnails`) VALUES (1, '2009/0225/zhaowei_mulan_s001.jpg'), (2, '2009/0225/zhaowei_mulan_s002.jpg'), (3, '2009/0225/zhaowei_mulan_s003.jpg'), (4, '2009/0312/zhaowei_mulan_s001.jpg'), (5, '2009/0316/zhaowei_post_s001.jpg'), ....About 75 more lines. EDIT: -- -- Dumping data for table `pho_pic` -- INSERT INTO `ocean_pictures` (`id`, `thumbnails`) VALUES (1, '2009/0225/zhaowei_mulan_s001.jpg'), (2, '2009/0225/zhaowei_mulan_s002.jpg'), (3, '2009/0225/zhaowei_mulan_s003.jpg'), (4, '2009/0312/zhaowei_mulan_s001.jpg'), (5, '2009/0316/zhaowei_post_s001.jpg'), ....About 75 more lines. Quote Link to comment https://forums.phpfreaks.com/topic/157162-solved-mysql-insert-into-issue/#findComment-828140 Share on other sites More sharing options...
Ken2k7 Posted May 7, 2009 Share Posted May 7, 2009 First and foremost, I am sincerely sorry for calling you a dude. I'll call you something sweeter now. Okay sweetie, this thread should be in the MySQL forums, not here in the PHP Help forum. But anyways, if your table you want to insert into has nothing (meaning it's empty), then you can TRUNCATE the table to wipe out all data so your ID will restart at one. Got it hun? Quote Link to comment https://forums.phpfreaks.com/topic/157162-solved-mysql-insert-into-issue/#findComment-828143 Share on other sites More sharing options...
phpocean Posted May 7, 2009 Author Share Posted May 7, 2009 Thanks. Sorry if I may sound stupid but as I am quite new to this world of php, would you be kind enough to show me a quite simple if it's not too much to ask? How would I incorporate TRUNCATE into this code? INSERT INTO `ocean_pictures` (`thumbnails`) VALUES ('2009/0225/zhaowei_mulan_s001.jpg'), ....About 79 more lines. If I use TRUNCATE, would that mean I'll have to input my other fields all over? Or just the id? I don't mind having my whole id replaced since it would basically be the same since my thumbnails field contains as much data as my currently id, which is 80. Quote Link to comment https://forums.phpfreaks.com/topic/157162-solved-mysql-insert-into-issue/#findComment-828148 Share on other sites More sharing options...
Ken2k7 Posted May 7, 2009 Share Posted May 7, 2009 Okay hun, here's the deal. I can't really decide because I need to know if the table ocean_pictures have any rows right now. I know you have your INSERT there, but what about the table right *NOW*. Does the ocean_pictures table have any data in it currently? Meaning before you ran that INSERT. Quote Link to comment https://forums.phpfreaks.com/topic/157162-solved-mysql-insert-into-issue/#findComment-828152 Share on other sites More sharing options...
phpocean Posted May 7, 2009 Author Share Posted May 7, 2009 hey Ken, To answer your question, yes it does. Currently table ocean_pictures has about six other fields and about 80 rows of valuable information. My auto_increment, which is my PRIMARY field is article_id, and it's currently at row 80. When I insert data in, it put them in my newly added field, starting at row 81, but I want it to start adding at row 1 into my new field, which is empty since it's a newly added field to my existing table. Hope this help. Quote Link to comment https://forums.phpfreaks.com/topic/157162-solved-mysql-insert-into-issue/#findComment-828160 Share on other sites More sharing options...
Ken2k7 Posted May 7, 2009 Share Posted May 7, 2009 Is it important though? What's wrong with 81? Would that mess up your SELECT SQL or something? Edit: Gotta head out for a bit. BBL Quote Link to comment https://forums.phpfreaks.com/topic/157162-solved-mysql-insert-into-issue/#findComment-828167 Share on other sites More sharing options...
phpocean Posted May 7, 2009 Author Share Posted May 7, 2009 I think it will, yes but I am not 100% sure because as I told you earlier, I'm quite new to php so I don't know how exactly php handle MySQL. Would it goes down the row until it find information on that field and then mark it as 1 or would it take it as 81? That is my question. But back to the TRUNCATE thing, have you forgotten about it? Or would the code be more than just a few lines, and that's why you resented to show me how to put data into new field starting from row 1? Edit............................................................. Why do you make yourself appeared offline, even when clearly you're online. ie don't see your name on online list. Quote Link to comment https://forums.phpfreaks.com/topic/157162-solved-mysql-insert-into-issue/#findComment-828178 Share on other sites More sharing options...
Ken2k7 Posted May 7, 2009 Share Posted May 7, 2009 TRUNCATE is no longer applicable now because it will delete all your rows. You forget, MySQL is very fast! If you just want to get an image at ID = 81, it can get that in milliseconds time. I can write that SQL for you if you would like. And it would treat it as row 81. When I put myself online, people PM me with questions too much asking me to view their help thread. But if you want, I'll allow you to PM me anytime you want. Not to make you uncomfortable. I just dislike people who have 1 post to be PMing me about questions when I have no obligation to answer their questions. Quote Link to comment https://forums.phpfreaks.com/topic/157162-solved-mysql-insert-into-issue/#findComment-828235 Share on other sites More sharing options...
phpocean Posted May 9, 2009 Author Share Posted May 9, 2009 That's very kind of you, but I've decided to update my newly added field through phpmyadmin, and just add new input to any field within that same table through phpmyadmin as I go. It's much more convenient that way. So you dislike gunk mail, I can't blame you, you have every right. Quote Link to comment https://forums.phpfreaks.com/topic/157162-solved-mysql-insert-into-issue/#findComment-830419 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.