PDA

View Full Version : Delete something unless id=1?



.:Jack120:.2
03-11-2007, 06:35 PM
Well, how do I make it so this deletes all the entrys unless the id of the entry is 1?
Code:

<?php
include "includes/config.php"; // config file

$query = mysql_query("TRUNCATE TABLE `timefriday` ;");

mysql_query("INSERT INTO `timefriday` VALUES ('00:00', '');") or exit("It didnt do it :(");
mysql_query("INSERT INTO `timefriday` VALUES ('01:00', '');") or exit("It didnt do it :(");
mysql_query("INSERT INTO `timefriday` VALUES ('02:00', '');") or exit("It didnt do it :(");
mysql_query("INSERT INTO `timefriday` VALUES ('03:00', '');") or exit("It didnt do it :(");
mysql_query("INSERT INTO `timefriday` VALUES ('04:00', '');") or exit("It didnt do it :(");
mysql_query("INSERT INTO `timefriday` VALUES ('05:00', '');") or exit("It didnt do it :(");
mysql_query("INSERT INTO `timefriday` VALUES ('06:00', '');") or exit("It didnt do it :(");
mysql_query("INSERT INTO `timefriday` VALUES ('07:00', '');") or exit("It didnt do it :(");
mysql_query("INSERT INTO `timefriday` VALUES ('08:00', '');") or exit("It didnt do it :(");
mysql_query("INSERT INTO `timefriday` VALUES ('09:00', '');") or exit("It didnt do it :(");
mysql_query("INSERT INTO `timefriday` VALUES ('10:00', '');") or exit("It didnt do it :(");
mysql_query("INSERT INTO `timefriday` VALUES ('11:00', '');") or exit("It didnt do it :(");
mysql_query("INSERT INTO `timefriday` VALUES ('12:00', '');") or exit("It didnt do it :(");
mysql_query("INSERT INTO `timefriday` VALUES ('13:00', '');") or exit("It didnt do it :(");
mysql_query("INSERT INTO `timefriday` VALUES ('14:00', '');") or exit("It didnt do it :(");
mysql_query("INSERT INTO `timefriday` VALUES ('15:00', '');") or exit("It didnt do it :(");
mysql_query("INSERT INTO `timefriday` VALUES ('16:00', '');") or exit("It didnt do it :(");
mysql_query("INSERT INTO `timefriday` VALUES ('17:00', '');") or exit("It didnt do it :(");
mysql_query("INSERT INTO `timefriday` VALUES ('18:00', '');") or exit("It didnt do it :(");
mysql_query("INSERT INTO `timefriday` VALUES ('19:00', '');") or exit("It didnt do it :(");
mysql_query("INSERT INTO `timefriday` VALUES ('20:00', '');") or exit("It didnt do it :(");
mysql_query("INSERT INTO `timefriday` VALUES ('21:00', '');") or exit("It didnt do it :(");
mysql_query("INSERT INTO `timefriday` VALUES ('21:00', '');") or exit("It didnt do it :(");
mysql_query("INSERT INTO `timefriday` VALUES ('23:00', '');") or exit("It didnt do it :(");

?>

Thank You :)

redtom
03-11-2007, 06:48 PM
DELETE FROM table WHERE id => 2

Not sure but would somthing like that work?

Invent
03-11-2007, 07:06 PM
DELETE FROM `table` WHERE `id` != '1'

.:Jack120:.2
03-11-2007, 07:12 PM
DELETE FROM table WHERE id => 2Not sure but would somthing like that work?
nope :(


DELETE FROM `table` WHERE `id` != '1'
That worked but when I run it, I get 2 entries :( So I end up with two 05:00
Whats the code so it dosnt duplicate =]

redtom
03-11-2007, 07:28 PM
nope :(

Change the => to >=

.:Jack120:.2
03-11-2007, 07:37 PM
Change the => to >=
Im using invents (Ill +Rep you when/if I get my other account back for helping)

But because its our timetable and we dont want two 02:00 slots (Because one is id 1) how do we do it. we tried (Below) but didnt work.


mysql_query("INSERT IGNORE INTO `timefriday` VALUES ('02:00', '', '');") or exit("It didnt do it :(");
but still adds an id=0 :(

redtom
03-11-2007, 08:31 PM
Im using invents (Ill +Rep you when/if I get my other account back for helping)

But because its our timetable and we dont want two 02:00 slots (Because one is id 1) how do we do it. we tried (Below) but didnt work.


mysql_query("INSERT IGNORE INTO `timefriday` VALUES ('02:00', '', '');") or exit("It didnt do it :(");
but still adds an id=0 :(

Wouldn't updating instead of inserting be easyer?

.:Jack120:.2
03-11-2007, 09:16 PM
Wouldn't updating instead of inserting be easyer?
yea =]

Im crap with these :(


<?php
include "includes/config.php"; // config file
mysql_query("UPDATE `timetest` SET ('00:00', '', '0') WHERE `id` != '1' ;") or exit("Could not import the sunday timetable data");
mysql_query("UPDATE `timetest` SET ('01:00', '', '0') WHERE `id` != '1' ;") or exit("Could not import the sunday timetable data");
mysql_query("UPDATE `timetest` SET ('02:00', '', '0') WHERE `id` != '1' ;") or exit("Could not import the sunday timetable data");
mysql_query("UPDATE `timetest` SET ('03:00', '', '0') WHERE `id` != '1' ;") or exit("Could not import the sunday timetable data");
mysql_query("UPDATE `timetest` SET ('04:00', '', '0') WHERE `id` != '1' ;") or exit("Could not import the sunday timetable data");
mysql_query("UPDATE `timetest` SET ('05:00', '', '0') WHERE `id` != '1' ;") or exit("Could not import the sunday timetable data");
mysql_query("UPDATE `timetest` SET ('06:00', '', '0') WHERE `id` != '1' ;") or exit("Could not import the sunday timetable data");
mysql_query("UPDATE `timetest` SET ('07:00', '', '0') WHERE `id` != '1' ;") or exit("Could not import the sunday timetable data");
mysql_query("UPDATE `timetest` SET ('08:00', '', '0') WHERE `id` != '1' ;") or exit("Could not import the sunday timetable data");
mysql_query("UPDATE `timetest` SET ('09:00', '', '0') WHERE `id` != '1' ;") or exit("Could not import the sunday timetable data");
mysql_query("UPDATE `timetest` SET ('10:00', '', '0') WHERE `id` != '1' ;") or exit("Could not import the sunday timetable data");
mysql_query("UPDATE `timetest` SET ('11:00', '', '0') WHERE `id` != '1' ;") or exit("Could not import the sunday timetable data");
mysql_query("UPDATE `timetest` SET ('12:00', '', '0') WHERE `id` != '1' ;") or exit("Could not import the sunday timetable data");
mysql_query("UPDATE `timetest` SET ('13:00', '', '0') WHERE `id` != '1' ;") or exit("Could not import the sunday timetable data");
mysql_query("UPDATE `timetest` SET ('14:00', '', '0') WHERE `id` != '1' ;") or exit("Could not import the sunday timetable data");
mysql_query("UPDATE `timetest` SET ('15:00', '', '0') WHERE `id` != '1' ;") or exit("Could not import the sunday timetable data");
mysql_query("UPDATE `timetest` SET ('16:00', '', '0') WHERE `id` != '1' ;") or exit("Could not import the sunday timetable data");
mysql_query("UPDATE `timetest` SET ('17:00', '', '0') WHERE `id` != '1' ;") or exit("Could not import the sunday timetable data");
mysql_query("UPDATE `timetest` SET ('18:00', '', '0') WHERE `id` != '1' ;") or exit("Could not import the sunday timetable data");
mysql_query("UPDATE `timetest` SET ('19:00', '', '0') WHERE `id` != '1' ;") or exit("Could not import the sunday timetable data");
mysql_query("UPDATE `timetest` SET ('20:00', '', '0') WHERE `id` != '1' ;") or exit("Could not import the sunday timetable data");
mysql_query("UPDATE `timetest` SET ('21:00', '', '0') WHERE `id` != '1' ;") or exit("Could not import the sunday timetable data");
mysql_query("UPDATE `timetest` SET ('22:00', '', '0') WHERE `id` != '1' ;") or exit("Could not import the sunday timetable data");
mysql_query("UPDATE `timetest` SET ('23:00', '', '0') WHERE `id` != '1' ;") or exit("Could not import the sunday timetable data");

?>

Beau
03-11-2007, 10:10 PM
yea =]

Im crap with these :(


<?php
include "includes/config.php"; // config file
mysql_query("UPDATE `timetest` SET ('00:00', '', '0') WHERE `id` != '1' ;") or exit("Could not import the sunday timetable data");
mysql_query("UPDATE `timetest` SET ('01:00', '', '0') WHERE `id` != '1' ;") or exit("Could not import the sunday timetable data");
mysql_query("UPDATE `timetest` SET ('02:00', '', '0') WHERE `id` != '1' ;") or exit("Could not import the sunday timetable data");
mysql_query("UPDATE `timetest` SET ('03:00', '', '0') WHERE `id` != '1' ;") or exit("Could not import the sunday timetable data");
mysql_query("UPDATE `timetest` SET ('04:00', '', '0') WHERE `id` != '1' ;") or exit("Could not import the sunday timetable data");
mysql_query("UPDATE `timetest` SET ('05:00', '', '0') WHERE `id` != '1' ;") or exit("Could not import the sunday timetable data");
mysql_query("UPDATE `timetest` SET ('06:00', '', '0') WHERE `id` != '1' ;") or exit("Could not import the sunday timetable data");
mysql_query("UPDATE `timetest` SET ('07:00', '', '0') WHERE `id` != '1' ;") or exit("Could not import the sunday timetable data");
mysql_query("UPDATE `timetest` SET ('08:00', '', '0') WHERE `id` != '1' ;") or exit("Could not import the sunday timetable data");
mysql_query("UPDATE `timetest` SET ('09:00', '', '0') WHERE `id` != '1' ;") or exit("Could not import the sunday timetable data");
mysql_query("UPDATE `timetest` SET ('10:00', '', '0') WHERE `id` != '1' ;") or exit("Could not import the sunday timetable data");
mysql_query("UPDATE `timetest` SET ('11:00', '', '0') WHERE `id` != '1' ;") or exit("Could not import the sunday timetable data");
mysql_query("UPDATE `timetest` SET ('12:00', '', '0') WHERE `id` != '1' ;") or exit("Could not import the sunday timetable data");
mysql_query("UPDATE `timetest` SET ('13:00', '', '0') WHERE `id` != '1' ;") or exit("Could not import the sunday timetable data");
mysql_query("UPDATE `timetest` SET ('14:00', '', '0') WHERE `id` != '1' ;") or exit("Could not import the sunday timetable data");
mysql_query("UPDATE `timetest` SET ('15:00', '', '0') WHERE `id` != '1' ;") or exit("Could not import the sunday timetable data");
mysql_query("UPDATE `timetest` SET ('16:00', '', '0') WHERE `id` != '1' ;") or exit("Could not import the sunday timetable data");
mysql_query("UPDATE `timetest` SET ('17:00', '', '0') WHERE `id` != '1' ;") or exit("Could not import the sunday timetable data");
mysql_query("UPDATE `timetest` SET ('18:00', '', '0') WHERE `id` != '1' ;") or exit("Could not import the sunday timetable data");
mysql_query("UPDATE `timetest` SET ('19:00', '', '0') WHERE `id` != '1' ;") or exit("Could not import the sunday timetable data");
mysql_query("UPDATE `timetest` SET ('20:00', '', '0') WHERE `id` != '1' ;") or exit("Could not import the sunday timetable data");
mysql_query("UPDATE `timetest` SET ('21:00', '', '0') WHERE `id` != '1' ;") or exit("Could not import the sunday timetable data");
mysql_query("UPDATE `timetest` SET ('22:00', '', '0') WHERE `id` != '1' ;") or exit("Could not import the sunday timetable data");
mysql_query("UPDATE `timetest` SET ('23:00', '', '0') WHERE `id` != '1' ;") or exit("Could not import the sunday timetable data");

?>

The above works? Or do you still need help?

.:Jack120:.2
03-11-2007, 10:10 PM
The above works? Or do you still need help?
Still need help please =]

Beau
03-11-2007, 10:20 PM
What is your database schema? Like, what fields have you got? Are you sure you're not making the ID NULL or 0? Looking at the SQL you're running, it looks like you might be...

.:Jack120:.2
04-11-2007, 02:26 PM
What is your database schema? Like, what fields have you got? Are you sure you're not making the ID NULL or 0? Looking at the SQL you're running, it looks like you might be...

slot
time
id

Beau
05-11-2007, 05:21 AM
You're settting you're ID column to NULL...

Try this:



mysql_query("UPDATE `timetest` SET (slot, time) VALUES ('', '22:00') WHERE `id` != '1' ;") or exit("Could not import the sunday timetable data");

Want to hide these adverts? Register an account for free!