Forums

PHP

This topic is locked

using check box too delete records ( PHPAKT)

Posted 13 Sep 2001 12:53:46
1
has voted
13 Sep 2001 12:53:46 dyna c posted:
is there a way to have a detail page where more than one record can be deleted at once.

for example if I create a page that list 10 records. I want to use a check box to select records to be deleted and delete the selected records.

Hopes this makes sense

Can you point me in the right direction

detail page


Edited by - on 09/13/2001 17:58:03

Replies

Replied 14 Sep 2001 11:55:11
14 Sep 2001 11:55:11 Tim Green replied:
I have written the following code to illustrate how to do this. You will have to amend all the recordset details, and the SQL used etc.

This code works perfectly for me, and hopefully it will serve as a starting point for you.

Just copy and paste it into a new blank document.

I hope this is of help.

Tim Green

Extension & PHP TalkZone Manager
<font size=1>-------------------------------------------
<i>Please read the Forum FAQ before posting
a question to this TalkZone.</i>
-------------------------------------------
www.UDzone.com : A dynamic Dreamweaver,
Ultradev and Fireworks site for developers
by developers.
-------------------------------------------</font id=size1>

Edited by - rawveg on 09/14/2001 11:56:52
Replied 14 Sep 2001 11:58:20
14 Sep 2001 11:58:20 Tim Green replied:
<pre id=code><font face=courier size=2 id=code>
&lt;?php


// Copyright (c) Interakt Online 2001
// www.interakt.ro/

require("./../adodb/adodb.inc.php";
require("./../Connections/connTest.php";
?&gt;&lt;?php
// If variable $formSeen has been set then process form parameters
if (isset($HTTP_POST_VARS["formSeen"])) {
$theDeletes = explode(",",$HTTP_POST_VARS["theValues"]);
$theSQL = "DELETE FROM Products WHERE ";
for ($k=0; $k &lt; count($theDeletes); $k++) {
if ($k &gt; 0) {
$theSQL.=" OR ";
}
$theSQL.="ID = '".$theDeletes[$k]."'";
}
echo $theSQL;
$theDelRS = $connTest-&gt;Execute($theSQL) or DIE($connTest-&gt;ErrorMsg());
}
?&gt;&lt;?php
$Recordset1=$connTest-&gt;Execute("SELECT * FROM Products" or DIE($connTest-&gt;ErrorMsg());
$Recordset1_numRows=0;
$Recordset1__totalRows=$Recordset1-&gt;RecordCount();
?&gt;&lt;?php
$Repeat1__numRows = 10;
$Repeat1__index= 0;
$Recordset1_numRows = $Recordset1_numRows + $Repeat1__numRows;
?&gt;
&lt;html&gt;
&lt;head&gt;
&lt;title&gt;Multiple Delete Example&lt;/title&gt;
&lt;meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"&gt;
&lt;script language="Javascript"&gt;

function MM_findObj(n, d) { //v4.0
var p,i,x; if(!d) d=document; if((p=n.indexOf("?")&gt;0&&parent.frames.length) {
d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i&lt;d.forms.length;i++) x=d.forms[i][n];
for(i=0;!x&&d.layers&&i&lt;d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
if(!x && document.getElementById) x=document.getElementById(n); return x;
}

function checkChange(theField) {
var currValue = MM_findObj(theField).value;
var blankCurr = false;

var theCurValues = MM_findObj("theValues".value;
if (theCurValues == "" {
blankCurr=true;
}
var theValueArray = theCurValues.split(",";
theValueArray.push(currValue);

var theValueString=theValueArray.join(",";
if (blankCurr) {
theValueString=theValueString.substr(1);
}
MM_findObj("theValues".value=theValueString;
}

&lt;/script&gt;
&lt;/head&gt;
&lt;body bgcolor="#FFFFFF" text="#000000"&gt;
&lt;form name="form1" method="post" action="&lt;?php echo $PHP_SELF; ?&gt;"&gt;
&lt;table width="50%" border="0" cellspacing="0" cellpadding="2" align="center"&gt;
&lt;tr&gt;
&lt;td width="2%"&gt; &lt;/td&gt;
&lt;td width="98%"&gt;Part Number&lt;/td&gt;
&lt;/tr&gt;
&lt;?php while (($Repeat1__numRows-- != 0) && (!$Recordset1-&gt;EOF))
{
?&gt;
&lt;tr&gt;
&lt;td height="20" width="2%"&gt;
&lt;input type="checkbox" name="checkbox&lt;?php echo $Recordset1-&gt;Fields("ID"?&gt;" value="&lt;?php echo $Recordset1-&gt;Fields("ID"?&gt;" onClick="checkChange('checkbox&lt;?php echo $Recordset1-&gt;Fields("ID"?&gt;')"&gt;
&lt;/td&gt;
&lt;td height="20" width="98%"&gt;
&lt;?php echo $Recordset1-&gt;Fields("PARTNO"?&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;?php
$Repeat1__index++;
$Recordset1-&gt;MoveNext();
}
?&gt;
&lt;/table&gt;
&lt;p align="center"&gt;
&lt;input type="hidden" name="formSeen" value="true"&gt;
&lt;input type="hidden" name="theValues"&gt;
&lt;input type="submit" name="Submit" value="Submit"&gt;
&lt;/p&gt;
&lt;/form&gt;
&lt;/body&gt;
&lt;/html&gt;
&lt;?php
$Recordset1-&gt;Close();
?&gt;
</font id=code></pre id=code>

Edited by - rawveg on 09/14/2001 12:01:09
Replied 14 Sep 2001 14:38:26
14 Sep 2001 14:38:26 dyna c replied:
code works a treat - thanks

It works well with the PHP insert record behaviour.

again thanks

Replied 14 Sep 2001 20:19:09
14 Sep 2001 20:19:09 Tim Green replied:
It's a pleasure. I tried to keep in mind that you might want to use other behaviours with the page (Insert/Update/Delete records etc).

If I get chance I will turn this into a behaviour (or Live Object) so that it can be easily implemented in the future.

Tim Green

Extension & PHP TalkZone Manager
<font size=1>-------------------------------------------
<i>Please read the Forum FAQ before posting
a question to this TalkZone.</i>
-------------------------------------------
www.UDzone.com : A dynamic Dreamweaver,
Ultradev and Fireworks site for developers
by developers.
-------------------------------------------</font id=size1>

Reply to this topic