I have tried for a while with no success to get this to work and I have tried countless methods and ideas, but I'm hitting roadblocks that are stopping my ideas.
Here is the situation:
I am trying to create a system for adding and deleting events, etc. I have the adding part down fine, but the script for deleting events that I am trying to make is more complicated.
I have the script display the events that meet the criteria that you set and I want there to be a checkbox by each one so you can check which events you want to delete. I have that part down. The part I am having trouble with is having the script delete multiple events that are checked. What I am trying to do is send the values of the check boxes and everything else in the form to another page where I would retrieve the info and have it delete the checked events from the previous page. I don't know if there is a better way to do this, or any way to do it. I'm hitting a blank wall. I'm sure there must be some way to do it, but I would appreciate it if someone could point me in the right direction. If I wasn't clear enough or you need clarification, I will be happy to explain the best I can, of even give you the link to the page I am working on if it would help.
Thanks in advance.
Creating an Event System
Moderator: General Moderators
-
DarkLightning
- Forum Newbie
- Posts: 3
- Joined: Tue Jul 01, 2003 3:51 am
- Location: Washington State
- Contact:
Name the checkboxes del[] ie:
Put in the value part the UNIQUE key.
Then the code sould sound like:
Code: Select all
<input type="checkbox" name="deleteї]" value="$id">Then the code sould sound like:
Code: Select all
if(isset($_POST["delete"])){
for($t1=0;$t1<sizeof($_POST["delete"]));$t1++){
$query = "DELETE FROM `table` WHERE `id`='".$_POST["delete"][$t1]."'";
if(!mysql_query($query)){
echo mysql_error()."\n";
echo $query;
exit;
}
}
}-
DarkLightning
- Forum Newbie
- Posts: 3
- Joined: Tue Jul 01, 2003 3:51 am
- Location: Washington State
- Contact:
Thank you
Thanx for your help. After correcting two slight errors in your script, it works now. Thank you so much.
Maybe you could help me with another question I had. If not, don't worry about it. But, is there an easy way to create a query that will select all events that match your search options taking into account the fact that if a field is left blank, then it should ignore the field. For example.
If I leave the month blank and select the day as the 28th, it would know to search for all events in any month that occur on the 28th. Or if I leave all the fields blank except for the year. You would show all events for that year. I can do this if I make some 12 if-then statements for every situation, but that is definitely not practical. Do you know of an alternative?
Maybe you could help me with another question I had. If not, don't worry about it. But, is there an easy way to create a query that will select all events that match your search options taking into account the fact that if a field is left blank, then it should ignore the field. For example.
If I leave the month blank and select the day as the 28th, it would know to search for all events in any month that occur on the 28th. Or if I leave all the fields blank except for the year. You would show all events for that year. I can do this if I make some 12 if-then statements for every situation, but that is definitely not practical. Do you know of an alternative?
- Heavy
- Forum Contributor
- Posts: 478
- Joined: Sun Sep 22, 2002 7:36 am
- Location: Viksjöfors, Hälsingland, Sweden
- Contact:
Personally I would:[]InTeR[] wrote:Code: Select all
if(isset($_POST["delete"])){ for($t1=0;$t1<sizeof($_POST["delete"]));$t1++){ $query = "DELETE FROM `table` WHERE `id`='".$_POST["delete"][$t1]."'"; if(!mysql_query($query)){ echo mysql_error()."\n"; echo $query; exit; } } } ?>
Code: Select all
<?php
if(isset($_POST['delete'])){
foreach ($_POST['delete'] as $DeleteID){
$whereCondition .= ($whereCondition != '' ? ' or' : '') . ' id= '''.addslashes($DeleteID).'''';
}
mysql_query('delete from table WHERE ' . $whereCondition) or die('Deletion query error: ' . mysql_error());
}
?>- twigletmac
- Her Royal Site Adminness
- Posts: 5371
- Joined: Tue Apr 23, 2002 2:21 am
- Location: Essex, UK
You can then use mysql_affected_rows() to check that the number of records you expected to have been deleted have been.Heavy wrote:it makes one query instead of one for each event.
Mac