View Full Version : deleting data from 2 fields but not the whole row
big-dog1965
05-25-2009, 04:58 AM
Is there a way to delete data from 2 fields in a table record?
I have a table with date1, time1, date2, time2, date3, time3, date4, time4
I would like to delete the data from date1, and time1
Something like this
DELETE FROM Venues WHERE DATE_SUB(CURDATE(),INTERVAL 1 DAY) >= `Date1`';
but not the whole row also instead of just the date1 field delete the time1 field data as well then when the next date is 1 day old it deletes date2 and time2. and so on till date4 and time4 is 1 day old and it deletes the record.
I’m using a webpage to display records and want it to be updated or only show date and time if the date and corresponding time field is not in the past
guelphdad
05-25-2009, 04:53 PM
First thing you need to do is consider database normalization. From the description of your table, when you find that you repeat things like date1, date2, date3, date4 etc. it is a clue that your data is not correctly normalized.
Killermud
05-25-2009, 05:13 PM
guelphdad is correct by saying the setup of this table is not good.
But to your problem the way you solve it is not using the DELETE function, but use UPDATE. so it may be alittle like this :
UPDATE Venues SET date1=NULL AND time1=NULL WHERE DATE_SUB(CURDATE(),INTERVAL 1 DAY) >= `Date1`';
this should solve your problem
big-dog1965
05-25-2009, 05:41 PM
guelphdad is correct by saying the setup of this table is not good.
But to your problem the way you solve it is not using the DELETE function, but use UPDATE. so it may be alittle like this :
UPDATE Venues SET date1=NULL AND time1=NULL WHERE DATE_SUB(CURDATE(),INTERVAL 1 DAY) >= `Date1`';
this should solve your problem
I got 4 date_ and time_ fields I tried using update but in 3 lines then the 4th line was a delete for date and time _4. I get an error something about string That I don’t know what to do with.
Just curios how mite the setup of table be?
$query = "INSERT into `".$db_table."` (venue,address,date_1,time_1,date_2,time_2,date_3,time_3,date_4,time_4,host,host_email,venue_website ,venue_phone,logo_image) VALUES ('" . $_POST['venue'] . "','" . $_POST['address'] . "','" . $_POST['date_1'] . "','" . $_POST['time_1'] . "','" . $_POST['date_2'] . "','" . $_POST['time_2'] . "','" . $_POST['date_3'] . "','" . $_POST['time_3'] . "','" . $_POST['date_4'] . "','" . $_POST['time_4'] . "','" . $_POST['host'] . "','" . $_POST['host_email'] . "','" . $_POST['venue_website'] . "','" . $_POST['venue_phone'] . "','" . $_FILES['logo_image']['name'] . "')";
vBulletin® v3.8.2, Copyright ©2000-2009, Jelsoft Enterprises Ltd.