yarub Posted October 21, 2006 Share Posted October 21, 2006 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. Quote Link to comment Share on other sites More sharing options...
yarub Posted October 22, 2006 Author Share Posted October 22, 2006 Any takers? Quote Link to comment Share on other sites More sharing options...
fert Posted October 22, 2006 Share Posted October 22, 2006 try this[code]$result=@mysql_query("UPDATE table_name SET value1='$value', value2='$value2'",$cn) or die(mysql_error();[/code] Quote Link to comment Share on other sites More sharing options...
fenway Posted October 22, 2006 Share Posted October 22, 2006 If you mean update different rows that don't match a single condition with a single statement, then the answer is no. You'd have to issue a separate update statement for each UID. Quote Link to comment Share on other sites More sharing options...
yarub Posted October 23, 2006 Author Share Posted October 23, 2006 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. =\ Quote Link to comment Share on other sites More sharing options...
fenway Posted October 24, 2006 Share Posted October 24, 2006 Well, it really depends on how you've declared each of the fields in the HTML form. Did you use a common prefix for all related fields for each record? Quote Link to comment Share on other sites More sharing options...
yarub Posted October 24, 2006 Author Share Posted October 24, 2006 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. Quote Link to comment Share on other sites More sharing options...
fenway Posted October 24, 2006 Share Posted October 24, 2006 I was talking about the HTML output side first... but it sounds like you've found someone else who can get you going. Good luck. 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.