1 Replies - 286 Views - Last Post: 31 October 2013 - 08:17 AM

#1 buzzard king  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 18
  • Joined: 23-October 13

concatenate two arrays, insert one by one into sql database

Posted 31 October 2013 - 08:14 AM

hi, This is a bit of a difficult question to ask so I will first of all run you all through what my program is about and how it works, then I will ask my question 0_0/>

The program is a bespoke calendar for cycle events (for charity) made from HTML/CSS/JQUERY/AJAX(JQUERY)/PHP/SQL the end goal for adding events to the calendar is this:

1) the user selects a day on the calendar
2) the user clicks a add icon (link)
3) they are sent to a event form page made of 3 parts these are a list of volunteers, list of cyclist, and a events information form (date, time start, time end, type and note)
4) the user will tick all of the volunteers/cyclist that they want to attend the event, fill out the event information and then hit save :^:/>

when the user hits the save button this is what i want to happen code wise:

1) a new row will be added to the event_diary table (event_id, event_location, event_start_time, event_end_time, _event_type, event_note, event_date, status), the status field is just for if the event is deleted or w.e

2)a second table "event_attendees" (event_id, cyclist_id, status) the status field is later used in the program for if the person actually attended the event, this table will be populated with a row for each volunteer/cyclist that the user ticked.

what I have done so far:

when a user ticks a volunteer or cyclist it is added to a jquery array:

here is the volunteer one:

$(document).on("click", ".selected_volunteer", function (e) {
    if ($(this).hasClass('volunteer_added')) {
        $("a", this).css('background-position', '-0px -20px');
        $(this).removeClass('volunteer_added');
        var add_volunteers_string = '';
        var data = '';
        var itemtoRemove = $(this).attr('name');
        volunteersThatAreTicked.splice($.inArray(itemtoRemove, volunteersThatAreTicked), 1);
        //CREATE ARRAY OF ADDED VOLUNTEERS
        $.each(volunteersThatAreTicked, function (index, value) {
            data = 'cyclist_id=' + value;
            $.ajax({
                url: "update_volunteer_added_to_event.php",
                type: "POST",
                data: data,
                success: function (html) {
                    add_volunteers_string = add_volunteers_string + html;
                    $('#show_added_volunteers').html(add_volunteers_string);
                }
            });
        });
        //DISPLAY THE ARRAY
        $('#show_added_volunteers').html(add_volunteers_string);
    } else {
        $("a", this).css('background-position', '-25px -0px');
        $(this).addClass('volunteer_added');
        volunteersThatAreTicked.push($(this).attr('name'));
        var add_volunteers_string = '';
        var data = '';
        //CREATE ARRAY OF ADDED CYCLISTS
        $.each(volunteersThatAreTicked, function (index, value) {
            data = 'cyclist_id=' + value;
            $.ajax({
                url: "update_volunteer_added_to_event.php",
                type: "POST",
                data: data,
                success: function (html) {
                    add_volunteers_string = add_volunteers_string + html;
                    $('#show_added_volunteers').html(add_volunteers_string);
                }
            });
        });
        //DISPLAY THE ARRAY
        $('#show_added_volunteers').html(add_volunteers_string);
    }
});



this is done the same way for cyclist

and this is how i am entering the information into the database on the click of the save button:

//SAVE EVENT TO THE DATABASE
$(document).on("click", ".save_event", function (e) {
    var event_
    $.ajax({
        url: "save_event.php",
        type: "POST",
        data: data,
        onloading: LOADING_GIF,
        success: function (html) {
            LOADING_GIF;
            SUCCESS_BOX;
            var data = "event_id=" + html; //the event_id used while running save_event.php is put here
            //here i want to added all the cyclist/volunteers (as one whole list as a volunteers and cyclist is determined by a type field in the cyclist table)
        }
    });
});



so i would have to some how illiterate through a concatenation of both the volunteers and cyclist jquery array and then insert them one by one via ajax/php ???? how!!?? :helpsmilie:/>

Is This A Good Question/Topic? 0
  • +

Replies To: concatenate two arrays, insert one by one into sql database

#2 modi123_1  Icon User is online

  • Suitor #2
  • member icon



Reputation: 8937
  • View blog
  • Posts: 33,495
  • Joined: 12-June 08

Re: concatenate two arrays, insert one by one into sql database

Posted 31 October 2013 - 08:17 AM

Please do not create duplicate topics. Closing.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1