Re: PHP webpage like MySQL, PART 2

From: Date: Thu, 24 Jul 2003 21:11:36 +0000
Subject: Re: PHP webpage like MySQL, PART 2
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-156744@lists.php.net to get a copy of this message
Are you talking about editing mutiple rows at the same time? if so there is no efficient way to check what row has been edited and which haven't. What I would is use HTML variable arrays for the names of the fields. example you have <input type='text' name='FirstName' size='20' maxlength='20' value='Allison' > change the name attribute to name = [data][$id][FirstName], so now you have all variables grouped (note the use if a fixed index 'data', explination in foreach loop ). Then your script will loop through the POST variables and do sequential UPDATES example foreach ($_POST[data] as $ID => $Field) { $query = " Update tablename Set First = '$Field[FirstName'], Last = '$Field[LastName'], .... Where id = $ID"; #List all fields in the set clause mysql_query($query); } The reason for the initial 'data' index is so you can safely loop through a cetrain part of the post array. If you left that out you would deal with extra variables like submit, and other hidden fields. It's a little hard to work with multi-dimensional arrays, so what I usually do to help me is use the var_dump() on the passed POST array. So take a look at var_dimp(), HTML with array indexes, the foreach loop construct. HOWEVER, if you need to just let the user edit 1 row, what you have is fine all you have to do is pass the id number thourgh a HTML hidden field. So when you pull the rest of the fields and spitting out HTML spit this out somewhere in between the <form> tags :: <input type='hidden' name='id' value='$id' > Bobby "Matt Hedges" <matt@hedges.org> wrote in message news:20030724202124.43947.qmail@pb1.pair.com... > Many hanks for ya'lls help earlier. > > I've figured out how to pull the data and edit it: > http://www.hedges.org/aoii/olemiss/updatesister.php > > However, for some reason I can't get it to edit whatever row. In the code > (pasted below) I have to specificy $id=row to edit... > > I can't figure out how to make it to where the user can select the field > (which is the id/row) and edit it. I've tried putting a ?id=# at the end of > the url, but that doesn't work... Any thoughts? So what I want is where it > says > > $id=1 > > to have it someway where that is a variable that the user can define... > > > > > Thank you. > Matt > > > > -- > ___________________________ > | Matt Hedges > | http://hedgesinnovations.com > | > >

« previous php.general (#156744) next »