Jump to content

[Solved] Update Multiple Rows At Once


yarub

Recommended Posts

Can someone tell me the process in updating multiple rows at once? I've been updating one row at a time with:
[code]$result = mysql_query("UPDATE tablename SET field='$field'")
or die(mysql_error());[/code]
I'm curious as to how I could have multiple rows at once, and then edit them all all at one time. Let's use a user database as an example. Right now, I just print out every single user with a link as their name which takes me to their own page. I'd like to be able to edit the page in which they all print out.

Username: [ yarub ] Password: [ **** ] Email: [ yarub@yarub.com ]
Username: [ fred ] Password: [ **** ] Email: [ fred@yarub.com ]
Username: [ john ] Password: [ **** ] Email: [ john@yarub.com ]
[ update ]

The brackets represent input fields obviously. Can someone run me through the process of making this work? I have absolutely no idea and can't find any tutorials on it.

Thanks.

EDIT: Solved! Got some help from someone. Thanks to those who attempted to help me.
Link to comment
Share on other sites

Well, I have absolutely no idea where to start. For the database, I'll just say I have four fields: id, user, password, and email. The id is set to primary and auto inc. I'm looking for a way to update every single row by clicking the update button at the bottom.

I know that it's possible to do that because I've seen it on other scripts. I'm just looking for something simple and something I can understand. My friend said it might involve a "loop" or a "foreach" function... but I don't know anything about either. =\
Link to comment
Share on other sites

I'm not sure what you mean. Right now, just to get it working, I have the following fields: id, name, lastname, & email. The field "id" is primary and atuo inc. I'm not sure what you mean by prefix.

I literally have no idea where to even start with this. I don't know what I need for the field name. I don't know what I need for the actual function to make it update. I'm working with scratch here because I've never done it.
Link to comment
Share on other sites

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.