From angelo.rigo@globo.com Fri Nov 29 12:26:02 2002 Received: from localhost (postgresql.org [64.49.215.8]) by postgresql.org (Postfix) with ESMTP id 6A578475C98 for ; Fri, 29 Nov 2002 07:26:02 -0500 (EST) Received: from nplex.globo.com (email.globo.com [200.208.9.53]) by postgresql.org (Postfix) with ESMTP id AD027475C15 for ; Fri, 29 Nov 2002 07:26:01 -0500 (EST) Received: from [200.219.69.252] by nplex.globo.com with HTTP; Fri, 29 Nov 2002 10:25:39 -0200 Date: Fri, 29 Nov 2002 09:25:39 -0300 Message-ID: <3DCBFE22000971C3@riosf06.globoi.com> From: angelo.rigo@globo.com Subject: deleting records with php and checkboxes To: pgsql-php@postgresql.org MIME-Version: 1.0 Content-Type: text/plain; charset="ISO-8859-15" Content-Transfer-Encoding: quoted-printable X-Virus-Scanned: by AMaViS new-20020517 X-Archive-Number: 200211/92 X-Sequence-Number: 1674 Hi I have the folowing two php?s to delete records from my database wich is an event database, it works typing the id field and clicking delete I would like to put checkboxes in more than one record at time to delete then. To make my script more advanced. How can it be done? i think i could put a checkbox with the default value "off (or 0)" and make the delete.php delete the record with the checkbox with value "on (or 1)", but the details to do this i need to discover someone has passed by this situation, and could help me? "); printf ("IdCity= stateLocationDayMonthTimeEvent"); do { $myrow =3D pg_fetch_row ($result,$row); printf ("%s%s%s%s%s%s%s%s ",$myrow[0], $myrow[1], $myrow[2], $myrow[3], $myrow[4], $myrow[5], $myrow[= 6],$myrow[7]); $row++; } while ($row < $numrows); printf ("
"); pg_close($db); ?> Type the id to be deleted.
ID to Delete :
Above is the delete.php Deleted with sucess!
"); pg_close($db); ?> ________________________________________ A busca mais veloz e precisa da internet. Acesse agora: http://www.zoom.com= .br. From fbax@sympatico.ca Fri Nov 29 17:24:04 2002 Received: from localhost (postgresql.org [64.49.215.8]) by postgresql.org (Postfix) with ESMTP id D396C476018 for ; Fri, 29 Nov 2002 12:24:04 -0500 (EST) Received: from tomts6-srv.bellnexxia.net (tomts6.bellnexxia.net [209.226.175.26]) by postgresql.org (Postfix) with ESMTP id 21AD4475DBD for ; Fri, 29 Nov 2002 12:24:04 -0500 (EST) Received: from acer.sympatico.ca ([65.93.64.111]) by tomts6-srv.bellnexxia.net (InterMail vM.5.01.04.19 201-253-122-122-119-20020516) with ESMTP id <20021129172408.IKDO7805.tomts6-srv.bellnexxia.net@acer.sympatico.ca>; Fri, 29 Nov 2002 12:24:08 -0500 Message-Id: <5.1.1.6.0.20021129121142.009f6920@pop6.sympatico.ca> X-Sender: b1wudu74@pop6.sympatico.ca X-Mailer: QUALCOMM Windows Eudora Version 5.1.1 Date: Fri, 29 Nov 2002 12:22:14 -0500 To: angelo.rigo@globo.com, pgsql-php@postgresql.org From: Frank Bax Subject: Re: deleting records with php and checkboxes In-Reply-To: <3DCBFE22000971C3@riosf06.globoi.com> Mime-Version: 1.0 X-Virus-Scanned: by AMaViS new-20020517 Content-Transfer-Encoding: 8bit Content-Type: text/plain; x-avg-checked=avg-ok-1A742586; charset=us-ascii; format=flowed X-Archive-Number: 200211/93 X-Sequence-Number: 1675 At 07:25 AM 11/29/02, angelo.rigo@globo.com wrote: >I have the folowing two php?s to delete records from my database wich is >an event database, >it works typing the id field and clicking delete > >I would like to put checkboxes in more than one record at time to delete >then. To make my script more advanced. > >How can it be done? > >i think i could put a checkbox with the default value "off (or 0)" and make >the delete.php delete the record with the checkbox with value "on (or 1)", >but the details to do this i need to discover >someone has passed by this situation, and could help me? > >$db = pg_connect("dbname=thedb user=theuser"); >$query = "SELECT * FROM thetable"; >$result = pg_exec($db, $query); >if (!$result) {printf ("ERROR"); exit;} >$numrows = pg_numrows($result); >$row=0; >printf (" >"); >printf ("bgcolor='#66CCFF'>"); >do >{ >$myrow = pg_fetch_row ($result,$row); >printf ("bgcolor='$bgcolor'> >",$myrow[0], $myrow[1], $myrow[2], $myrow[3], $myrow[4], $myrow[5], >$myrow[6],$myrow[7]); >$row++; >} >while ($row < $numrows); >printf ("
IdCitystateLocationDayMonthTimeEvent
%s%s%s%s%s%s%s%s

>"); >pg_close($db); >?> > >Type the id to be deleted. > >
>ID to Delete :
> > >
> > >Above is the delete.php > > >$db = pg_connect("dbname=thedb user=theuser"); >$query = "DELETE FROM thetable where id='$id'"; >$result = pg_exec($db, $query); >if (!$result) {printf ("ERROR"); exit;} >printf ("Deleted with sucess!"); >pg_close($db); >?> Checkbox doesn't work like other form elements. Other form elements always get returned. Checkbox ony gets sent back when it is checked. Therefore, make the value of the checkbox the value of id you want deleted, make it's name an array like id[] instead of simply id. Then your delete code will look something like: $id = $HTTP_POST_VARS[id]; for( $n=0; $n < count($id); $n++ ) { if( strlen($id[$n])>0 ) { $sql="DELETE from thetable WHERE id='" . $id[$n] ."'"; pg_exec( $sql ); } }