Jump to content

[SOLVED] MYSQL DELETE problems


giraffemedia

Recommended Posts

Hi,

 

i'm having problems getting my delete query to work on an edit form. I'm using array_diff to work out the different values returned from a row of checkboxes that were pre populated from existing values in the database. This works fine and I have echoed the results to check that the correct values are returned - which they are. The next part of the form adds new values that don't already exist and once that is done I want to delete the values that are currently in the db but are no longer needed. Here is what I have...

 

// Use array_diff to check all differences in the two arrays of issues.  If not NULL define the two variables for add and delete. If no changes have been made declare both variables NULL
if ($new_issue_list != NULL) {
       $delete = array_diff($issues, $new_issue_list);
       $add = array_diff($new_issue_list, $issues);
   }
   else {
        $add = NULL;
        $delete = NULL;
   }

// Check if the $add variable is NULL. If it is don't do anything with the varibale, if it isn't run the mysql INSERT query
if ($add == NULL) {

}

else {

foreach( $add as $add_key => $add_value) {

mysql_query("INSERT INTO issues_booked (ib_id, ib_issue_number, ib_booking_form_number) VALUES ('','$add_value', '$bf_record')");

}

}

// Check if the $delete variable is NULL. If it is don't do anything with the varibale, if it isn't run the mysql DELETE query
if ($delete == NULL) {

}

else {

foreach( $delete as $key => $value) {

mysql_query("DELETE FROM issues WHERE ib_issue_number = '$value' AND ib_booking_form_number = '$bf_record'");

}

}

 

Anyone have any ideas?

Link to comment
Share on other sites

I'm not sure i understood exactly what you need done...

 

If you use mysql_query("DELETE FROM ...") -- this DELETES the entire row.

If you need to set certain fields in your table as blank or something use something like this:

 

$result = mysql_query("UPDATE issues SET field_name='$variable' WHERE id='$id' ")
		or die ("Could not read data because ".mysql_error());

 

or an other idea:

try usgin

$value = $_GET[value] or $value = $_POST[value] dependin on how the value is read, from a post or URL

same goes for $bf_record

 

Cheers

Link to comment
Share on other sites

I'm not sure i understood exactly what you need done...

 

If you use mysql_query("DELETE FROM ...") -- this DELETES the entire row.

 

That's what I want to do spasme. Each issue is held in a row and I want to delete the issues that are no longer needed.

 

Regards

 

James

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.