Drop/Delete id,titel,start,end from Database

Overzicht Reageren

Sponsored by: Vacatures door Monsterboard

E WNSMA

E WNSMA

20/11/2013 15:18:38
Quote Anchor link
Hallo mensen van het goede leven,
hieronder heb ik wat codes ingevoerd.

Echter werkt dit gewoon tot aan "delete" en "edit",
bij save wordt er een array in de database gecreeerd.
Wat ik nu wil is dat bij "delete" database delete doet,
van zelf sprekend.
Voor "edit" hetzelfde alleen i.p.v. database delete, database UPDATA/EDIT.

Er moet dus 2 lines toegevoegd worden dat er een update gedaan moet worden bij de database.

Ik zelf heb heel weinig kennis van programmeren/scripten,
ik ben meer een gebruiker.

JS FILE
Code (php)
PHP script in nieuw venster Selecteer het PHP script
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
$(document).ready(function() {


   var $calendar = $('#calendar');
   var id = 10;

   $calendar.weekCalendar({
      timeslotsPerHour : 4,
      allowCalEventOverlap : true,
      overlapEventsSeparate: true,
      firstDayOfWeek : 1,
      businessHours :{start: 8, end: 18, limitDisplay: true },
      daysToShow : 7,
      height : function($calendar) {
         return $(window).height() - $("h1").outerHeight() - 1;
      },
      eventRender : function(calEvent, $event) {
         if (calEvent.end.getTime() < new Date().getTime()) {
            $event.css("backgroundColor", "#aaa");
            $event.find(".wc-time").css({
               "backgroundColor" : "#999",
               "border" : "1px solid #888"
            });
         }
      },
      draggable : function(calEvent, $event) {
         return calEvent.readOnly != true;
      },
      resizable : function(calEvent, $event) {
         return calEvent.readOnly != true;
      },
      eventNew : function(calEvent, $event) {
         var $dialogContent = $("#event_edit_container");
         resetForm($dialogContent);
         var startField = $dialogContent.find("select[name='start']").val(calEvent.start);
         var endField = $dialogContent.find("select[name='end']").val(calEvent.end);
         var titleField = $dialogContent.find("input[name='title']");
         var bodyField = $dialogContent.find("textarea[name='body']");


         $dialogContent.dialog({
            modal: true,
            title: "New Calendar Event",
            close: function() {
               $dialogContent.dialog("destroy");
               $dialogContent.hide();
               $('#calendar').weekCalendar("removeUnsavedEvents");
            },
            buttons: {
               save : function() {
                  calEvent.id = id;
                  id++;
                  calEvent.start = new Date(startField.val());
                  calEvent.end = new Date(endField.val());
                  calEvent.title = titleField.val();
                  calEvent.body = bodyField.val();
                  
                  //post to events.php
                  $.post("events.php?action=save&start="+calEvent.start.getTime()/1000+"&end="+calEvent.end.getTime()/1000+"&title="+calEvent.title+"&body="+calEvent.body);

                  $calendar.weekCalendar("removeUnsavedEvents");
                  $calendar.weekCalendar("updateEvent", calEvent);
                  $dialogContent.dialog("close");
               },
               cancel : function() {
                  $dialogContent.dialog("close");
               }
            }
         }).show();

         $dialogContent.find(".date_holder").text($calendar.weekCalendar("formatDate", calEvent.start));
         setupStartAndEndTimeFields(startField, endField, calEvent, $calendar.weekCalendar("getTimeslotTimes", calEvent.start));

      },
      eventDrop : function(calEvent, $event) {
        
      },
      eventResize : function(calEvent, $event) {
      },
      eventClick : function(calEvent, $event) {

         if (calEvent.readOnly) {
            return;
         }

         var $dialogContent = $("#event_edit_container");
         resetForm($dialogContent);
         var startField = $dialogContent.find("select[name='start']").val(calEvent.start);
         var endField = $dialogContent.find("select[name='end']").val(calEvent.end);
         var titleField = $dialogContent.find("input[name='title']").val(calEvent.title);
         var bodyField = $dialogContent.find("textarea[name='body']");
         bodyField.val(calEvent.body);

         $dialogContent.dialog({
            modal: true,
            title: "Edit - " + calEvent.title,
            close: function() {
               $dialogContent.dialog("destroy");
               $dialogContent.hide();
               $('#calendar').weekCalendar("removeUnsavedEvents");
            },
            buttons: {
               save : function() {

                  calEvent.start = new Date(startField.val());
                  calEvent.end = new Date(endField.val());
                  calEvent.title = titleField.val();
                  calEvent.body = bodyField.val();

                  $calendar.weekCalendar("updateEvent", calEvent);
                  $dialogContent.dialog("close");
               },
               "delete" : function() {
                  $calendar.weekCalendar("removeEvent", calEvent.id);
                  $dialogContent.dialog("close");
               },
               cancel : function() {
                  $dialogContent.dialog("close");
               }
            }
         }).show();

         var startField = $dialogContent.find("select[name='start']").val(calEvent.start);
         var endField = $dialogContent.find("select[name='end']").val(calEvent.end);
         $dialogContent.find(".date_holder").text($calendar.weekCalendar("formatDate", calEvent.start));
         setupStartAndEndTimeFields(startField, endField, calEvent, $calendar.weekCalendar("getTimeslotTimes", calEvent.start));
         $(window).resize().resize(); //fixes a bug in modal overlay size ??

      },
      eventMouseover : function(calEvent, $event) {
      },
      eventMouseout : function(calEvent, $event) {
      },
      noEvents : function() {

      },
      data : "events.php"
   });

   function resetForm($dialogContent) {
      $dialogContent.find("input").val("");
      $dialogContent.find("textarea").val("");
   }

   /*
    * Sets up the start and end time fields in the calendar event
    * form for editing based on the calendar event being edited
    */
   function setupStartAndEndTimeFields($startTimeField, $endTimeField, calEvent, timeslotTimes) {

      for (var i = 0; i < timeslotTimes.length; i++) {
         var startTime = timeslotTimes[i].start;
         var endTime = timeslotTimes[i].end;
         var startSelected = "";
         if (startTime.getTime() === calEvent.start.getTime()) {
            startSelected = "selected=\"selected\"";
         }
         var endSelected = "";
         if (endTime.getTime() === calEvent.end.getTime()) {
            endSelected = "selected=\"selected\"";
         }
         $startTimeField.append("<option value=\"" + startTime + "\" " + startSelected + ">" + timeslotTimes[i].startFormatted + "</option>");
         $endTimeField.append("<option value=\"" + endTime + "\" " + endSelected + ">" + timeslotTimes[i].endFormatted + "</option>");

      }
      $endTimeOptions = $endTimeField.find("option");
      $startTimeField.trigger("change");
   }

   var $endTimeField = $("select[name='end']");
   var $endTimeOptions = $endTimeField.find("option");

   //reduces the end time options to be only after the start time options.
   $("select[name='start']").change(function() {
      var startTime = $(this).find(":selected").val();
      var currentEndTime = $endTimeField.find("option:selected").val();
      $endTimeField.html(
            $endTimeOptions.filter(function() {
               return startTime < $(this).val();
            })
            );

      var endTimeSelected = false;
      $endTimeField.find("option").each(function() {
         if ($(this).val() === currentEndTime) {
            $(this).attr("selected", "selected");
            endTimeSelected = true;
            return false;
         }
      });

      if (!endTimeSelected) {
         //automatically select an end date 2 slots away.
         $endTimeField.find("option:eq(1)").attr("selected", "selected");
      }

   });


   var $about = $("#about");

   $("#about_button").click(function() {
      $about.dialog({
         title: "About this calendar demo",
         width: 600,
         close: function() {
            $about.dialog("destroy");
            $about.hide();
         },
         buttons: {
            close : function() {
               $about.dialog("close");
            }
         }
      }).show();
   });


});



PHP FILE connect DATABASE
Code (php)
PHP script in nieuw venster Selecteer het PHP script
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
<?php

$action
= $_REQUEST['action'];

if (!$link = mysql_connect('localhost', 'root', '')) {
    echo 'Could not connect to mysql';
    exit;
}


if (!mysql_select_db('portal', $link)) {
    echo 'Could not select database';
    exit;
}


if($action == 'save')
{

    $title = $_REQUEST['title'];
    $body = $_REQUEST['body'];
    $start_time = (int)$_REQUEST['start'];
    $start_time = $start_time - 60*60;
    $end_time = (int)$_REQUEST['end'];
    $end_time = $end_time - 60*60;
    $start = date('c',$start_time);
    $end = date('c',$end_time);
    $sql = "INSERT INTO meeting_rooms_calendar(title,body,start,end) VALUES ('$title','$body','$start','$end')";
    $result = mysql_query($sql, $link);
}

else
{
    $sql= "SELECT id, title, body,
            DATE_FORMAT(start, '%Y-%m-%dT%H:%i' ) AS startTime, DATE_FORMAT(end, '%Y-%m-%dT%H:%i' ) AS endTime
           FROM meeting_rooms_calendar
           ORDER BY start DESC"
;
          
    $result = mysql_query($sql, $link);

    if (!$result) {
        echo "DB Error, could not query the database\n";
        echo 'MySQL Error: ' . mysql_error();
        exit;
    }


    $events = array();

    while ($row = mysql_fetch_assoc($result)) {
       $eventArray['id'] = $row['id'];
       $eventArray['title'] =  $row['title'];
       $eventArray['body'] =  $row['body'];
       $eventArray['start'] = $row['startTime'];
       $eventArray['end'] = $row['endTime'];
       $events[] = $eventArray;
    }


    echo json_encode($events);
}


/*
   echo json_encode(array(

      array(
         'id' => 1,
         'start' => "2012-07-08T08:30",
         'end' => "2012-07-08T09:30",
         'title' => "event1",
         'body' => "kaka"
      ),

      array(
         'id' => 2,
         'start' => "2012-07-09T08:30",
         'end' => "2012-07-09T09:30",
         'title' => "event2"
      )

   ));
*/


?>


SQL create
Code (php)
PHP script in nieuw venster Selecteer het PHP script
1
2
3
4
5
6
7
8
9
10
11
CREATE TABLE IF NOT EXISTS `meeting_rooms_calendar` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `userID` int(10) unsigned NOT NULL,
  `title` varchar(100) NOT NULL,
  `body` varchar(255) DEFAULT NULL,
  `start` datetime NOT NULL,
  `end` datetime NOT NULL,
  `editable` tinyint(1) NOT NULL,
  PRIMARY KEY (`id`),
  KEY `userID` (`userID`)
) ENGINE=InnoDB  DEFAULT CHARSET=latin1 AUTO_INCREMENT=0 ;


ter informatie dit is een open source, dus niet door mijzelf geknutseld.
Gewijzigd op 20/11/2013 15:21:17 door E WNSMA
 
PHP hulp

PHP hulp

26/11/2024 17:33:45
 
Nick Dijkstra

Nick Dijkstra

20/11/2013 20:04:58
Quote Anchor link
Bedoel je dit?
Code (php)
PHP script in nieuw venster Selecteer het PHP script
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
<?php
if($action == 'add')
{

// hier je code voor het toevoegen
}
elseif ($action == 'save')
{

// hier je code voor het opslaan
}
elseif ($action == 'delete')
{

// hier je code voor het verwijderen
}
else
{
// hier je code voor het ophalen
}
?>
 
E WNSMA

E WNSMA

20/11/2013 21:59:44
Quote Anchor link
Beste Nick Dijkstra,


ik ben niet zo goed daarin nu heb ik save wel alleen delete/edit krijg ik niet aan de praat.
Dit heb ik nog geprobeerd;
Het saven doet zoals verwacht, insert het in database, maar het delete optie verwijderd het niet van database
Code (php)
PHP script in nieuw venster Selecteer het PHP script
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
if($action == 'save')
{
    $title = $_REQUEST['title'];
    $body = $_REQUEST['body'];
    $start_time = (int)$_REQUEST['start'];
    $start_time = $start_time + 60*60;
    $end_time = (int)$_REQUEST['end'];
    $end_time = $end_time + 60*60;
    $start = date('c',$start_time);
    $end = date('c',$end_time);
    $sql = "INSERT INTO meeting_rooms_calendar(title,body,start,end) VALUES ('$title','$body','$start','$end')";
    $result = mysql_query($sql, $link);

}
elseif ($action == 'del')
{
    $del = "DELETE FROM `agenda`.`meeting_rooms_calendar` WHERE `meeting_rooms_calendar`.`id` = VALUES ('$id')";
    $result = mysql_query($del, $link);
}
else
{
    $sql= "SELECT id, title, body,
            DATE_FORMAT(start, '%Y-%m-%dT%H:%i' ) AS startTime, DATE_FORMAT(end, '%Y-%m-%dT%H:%i' ) AS endTime
           FROM meeting_rooms_calendar
           ORDER BY start DESC";

    $result = mysql_query($sql, $link);


Geen succces, delete doet zijn werk niet in database, namelijk het verwijderen van ID=x
Gewijzigd op 20/11/2013 22:02:40 door E WNSMA
 
Nick Dijkstra

Nick Dijkstra

20/11/2013 22:15:32
Quote Anchor link
Het is:

Code (php)
PHP script in nieuw venster Selecteer het PHP script
1
2
3
4
<?php
$del
= "DELETE FROM meeting_rooms_calendar WHERE id=" . $id;
$result = mysql_query($del, $link);
?>
 
E WNSMA

E WNSMA

20/11/2013 22:19:29
Quote Anchor link
Hij delete nog steeds niet, kan het misschien hieraan liggen.

Code (php)
PHP script in nieuw venster Selecteer het PHP script
1
2
3
4
5
6
7
"delete" : function() {
               calEvent.id = id;

               $.post("events.php?action=del&id="+calEvent.id);
              $calendar.weekCalendar("removeEvent", calEvent.id);
              $dialogContent.dialog("close");
           }
 
Nick Dijkstra

Nick Dijkstra

20/11/2013 22:45:16
Quote Anchor link
ik denk dat dit regeltje weg moet:

calEvent.id = id;
 
E WNSMA

E WNSMA

20/11/2013 23:11:28
Quote Anchor link
Nee helaas ook niet. Ik heb ook zo geprobeerd maar ook geen succes

Code (php)
PHP script in nieuw venster Selecteer het PHP script
1
2
3
4
5
6
7
8
9
10
11
12
13
14
"delete"  : function() {
                  calEvent.id = id;
                  id++;
                  calEvent.start = new Date(startField.val());
                  calEvent.end = new Date(endField.val());
                  calEvent.title = titleField.val();
                  calEvent.body = bodyField.val();
                  
                  //post to events.php
                  $.post("events.php?action=del&start="+calEvent.start.getTime()/1000+"&end="+calEvent.end.getTime()/1000+"&title="+calEvent.title+"&body="+calEvent.body);

                  $calendar.weekCalendar("removeEvent", calEvent.id);
                  $dialogContent.dialog("close");
                }

En in PHP

Code (php)
PHP script in nieuw venster Selecteer het PHP script
1
2
3
4
5
6
7
8
9
10
11
12
13
14
if($action == 'del')
{
    $title = $_REQUEST['title'];
    $body = $_REQUEST['body'];
    $start_time = (int)$_REQUEST['start'];
    $start_time = $start_time + 60*60;
    $end_time = (int)$_REQUEST['end'];
    $end_time = $end_time + 60*60;
    $start = date('c',$start_time);
    $end = date('c',$end_time);
    $sql = "DELETE FROM meeting_rooms_calendar(title,body,start,end) VALUES ('$title','$body','$start','$end')";
    $result = mysql_query($sql, $link);

}


Wat wel als save werkt werkt niet als ik DELETE FROM doe i.p.v. INSERT TO
Gewijzigd op 20/11/2013 23:13:52 door E WNSMA
 
Nick Dijkstra

Nick Dijkstra

20/11/2013 23:14:17
Quote Anchor link
Je moet zo doen:
Code (php)
PHP script in nieuw venster Selecteer het PHP script
1
2
3
4
<?php
$del
= "DELETE FROM meeting_rooms_calendar WHERE id=" . $id;
$result = mysql_query($del, $link);
?>


Niet zo:
Code (php)
PHP script in nieuw venster Selecteer het PHP script
1
2
3
4
<?php
sql = "DELETE FROM meeting_rooms_calendar(title,body,start,end) VALUES ('$title','$body','$start','$end')";
$result = mysql_query($sql, $link);
?>


Je wilt toch verwijderen, niet toe te voegen?
 
E WNSMA

E WNSMA

20/11/2013 23:19:27
Quote Anchor link
Ja dat werkte niet dus ik dacht als ik de code van save pak dat wel werkt.

Verander in delete dat het misschien wel zou werken maar dat ook zonder succes...





Toevoeging op 21/11/2013 15:54:30:

Oops, ik heb m gefixt.
Gewijzigd op 21/11/2013 13:07:01 door E WNSMA
 



Overzicht Reageren

 
 

Om de gebruiksvriendelijkheid van onze website en diensten te optimaliseren maken wij gebruik van cookies. Deze cookies gebruiken wij voor functionaliteiten, analytische gegevens en marketing doeleinden. U vindt meer informatie in onze privacy statement.