Jump to content

Recommended Posts

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.

Link to comment
https://forums.phpfreaks.com/topic/157162-solved-mysql-insert-into-issue/
Share on other sites

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.

 

 

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?

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.

 

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.

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.

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.

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.

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.