Page 1 of 1
Delete Multiple Records
Posted: Fri May 09, 2003 8:13 am
by igoy
I have a mysql table where there is no primary key, nothing like 'ID' or so. . I want to delete multiple records in this table using checkboxes ..
can it be possible....???
Posted: Fri May 09, 2003 8:29 am
by twigletmac
If you have nothing to uniquely identify a record then it's going to be a bit of a PITA. Create some unique ID for each record and you'll make your life much easier.
Mac
Posted: Fri May 09, 2003 6:24 pm
by JPlush76
you can add primary id's after the fact, I would suggest doing that
every table except maybe many to many should have a unique id
Hmmm
Posted: Sat May 10, 2003 1:32 am
by igoy
Well. . you can't help going by rules so i created unique ID column in the table. . . i did infact everything ele required .. .now. . still it's not deleting multiple records . . i'm using chekboxes to select the records . .and submitting to other php called delete.php .. .but it's not deleting multiple records .. it deletes the last one in selected records.
any suggestion . .??
Posted: Sat May 10, 2003 7:36 am
by Heavy
Your question involves to many unknown factors to answer. Tell us some more.
How does the record selection form look like (HTML with checkboxes)?
What distinguishes one record from another among your checkboxes?
How is the database table designed, what things are PRIMARY or UNIQUE?
How do you build the query to delete the records?
Any error messages?
Posted: Sat May 10, 2003 10:55 am
by JPlush76
I think you're looking for arrays
your checkbox field should be name=delete[]
that sets the check boxes up as an array, then when you process the form do a foreach on that field and loop through and delete the records
Still Lost !! :(
Posted: Sun May 18, 2003 8:30 am
by igoy
Hi Jplush,
Sorry for replying late.. I was out of town..
Back and still lost about multiple delete problem...

..sad
I tried creating array as you said but in vain ..
not ur fault. . it's my dumbness for not udnerstanding foreach() stuff..
basically I'm using Macromedia Dreamweaver MX for site creation and do some coding myself (as and when required)...
Posting below is Code Dreamweaver generated for Deleting Record..
( It can delete one record at a time ) ..
Code: Select all
<?
$table = $_GET['page'];
$goto = $page.".php";
?>
<?php require_once('../Connections/connpv.php'); ?>
<?php
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
$theValue = (!get_magic_quotes_gpc()) ? addslashes($theValue) : $theValue;
switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
break;
}
return $theValue;
}
if ((isset($HTTP_POST_VARS['delbox'])) && ($HTTP_POST_VARS['delbox'] != "")) {
$deleteSQL = sprintf("DELETE FROM $table WHERE rid=%s",
GetSQLValueString($HTTP_POST_VARS['delbox'], "int"));
mysql_select_db($database_connpv, $connpv);
$Result1 = mysql_query($deleteSQL, $connpv) or die(mysql_error());
}
?>
I hope i'm not expecting too much. . but you gyus are great hope for us amatuers ...
Thanks Again.