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: [ [email protected] ]
Username: [ fred ] Password: [ **** ] Email: [ [email protected] ]
Username: [ john ] Password: [ **** ] Email: [ [email protected] ]
[ 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
https://forums.phpfreaks.com/topic/24638-solved-update-multiple-rows-at-once/
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. =\
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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.