У меня проблема с получением нескольких раскрывающихся значений.После отправки он получает ошибку базы данных - PullRequest
0 голосов
/ 01 июня 2018

Просмотр:

<select class="form-control" data-placeholder="Choose a Category" tabindex="1" name="venues[]"  multiple >
    <option value="">Select One</option>    
    <?php foreach($list_of_venues as $venues){ ?>
    <option value="<?php echo $venues->activity_venue_id; ?>"><?php echo $venues->venue_title; ?></option>
    <?php } ?>
    </select>

Контроллер

<?php
defined('BASEPATH') OR exit('No direct script access allowed');

class Create_activity_session extends CI_Controller {

    function __construct()
    {
        parent::__construct();
        $this->load->model('vendor_model');
        $this->load->database();
    }
    public function index()
    {
        error_reporting(0);

        $session_data = $this->session->userdata('logged_in');
        $data['account_name'] = $session_data['account_name'];
        if($session_data['account_name']){

            $data['id'] = $session_data['id'];
            $id = $data['id'];
            $data['list_of_activities'] = $this->vendor_model->list_of_activities_by_vendor($id);
            $data['list_of_venues'] = $this->vendor_model->list_of_venues_by_vendor($id);
            $data['list_of_booking_fields'] = $this->vendor_model->list_of_booking_fields_by_vendor_by_venue($id);


            $this->form_validation->set_rules('activity_title','Activity Title','required');
            $this->form_validation->set_rules('venues[]','Selecting Venue','required');
            $this->form_validation->set_rules('start_date','Start Date','required');
            $this->form_validation->set_rules('end_date','End Date','required');
            $this->form_validation->set_rules('start_time','Start Time','required');
            $this->form_validation->set_rules('end_time','End Time','required');
            $this->form_validation->set_rules('number_of_seats','Number of Bookings','required');
            $this->form_validation->set_rules('price','Price','required');



            if($this->form_validation->run()==FALSE){
                $data['list_of_activities'] = $this->vendor_model->list_of_activities_by_vendor($id);
                $data['list_of_venues'] = $this->vendor_model->list_of_venues_by_vendor($id);
                $data['list_of_booking_fields'] = $this->vendor_model->list_of_booking_fields_by_vendor_by_venue($id);
                $this->load->view('vendor/create_activity_session',$data);
            } else {

                $end_date = $this->input->post('end_date');
                $start_date = $this->input->post('start_date');

                if($end_date < $start_date){
                    $data['error'] = 'Start Date should not be greater than the End Date.'; 
                    $this->load->view('vendor/create_activity_session',$data);
                } else {

                $activity_id = $this->input->post('activity_title');



                $venue_id = implode(',',$this->input->post('venues'));

                $data = array(
                        'activity_by_id' => $this->input->post('activity_title'),
                        'venue_id' => $venue_id,
                        'start_date' => $this->input->post('start_date'),
                        'end_date' => $this->input->post('end_date'),
                        'start_time' => $this->input->post('start_time'),
                        'end_time' => $this->input->post('end_time'),
                        'number_of_seats' => $this->input->post('number_of_seats'),
                        'price' => $this->input->post('price'),
                        'vendor_id' => $id,
                        'status' => 1,
                        'created_on' => date('Y-m-d h:i:s')

                );



                $result = $this->vendor_model->create_activity_dates_time($data);


                $session_id = $this->db->insert_id();

             //   $venues = $this->input->post('venues');

                $data = array(
                        'venue_activity_id' => $venue_id,

                );
                $result2 = $this->vendor_model->update_activity($data,$activity_id);




                $venues = $this->input->post('venues');

                $venue_count = count($venues);

                for($i = 0;$i<=$venue_count; $i++){



               $data = array(
                        'session_by_id' => $session_id,
                        'venue_by_id' => $venues[$i]

                );


                $result3 = $this->vendor_model->create_venues_by_session($data); 

                }

                $data['success'] = 'You have created the new Activity Session'; 




                $data['list_of_activities'] = $this->vendor_model->list_of_activities_by_vendor($id);
                $data['list_of_venues'] = $this->vendor_model->list_of_venues_by_vendor($id);
                $data['list_of_booking_fields'] = $this->vendor_model->list_of_booking_fields_by_vendor_by_venue($id);
                 $this->load->view('vendor/create_activity_session',$data);
        }
        } 

    }  else {
            redirect('http://localhost/bookleisure/vendor/login');
        }
    }
}

У меня проблема с вставкой нескольких раскрывающихся значений, отображающих базу данныхошибка

venue_by_id не может быть нулевым.

Я хотел вставить несколько раскрывающихся строк.

1 Ответ

0 голосов
/ 01 июня 2018

попробуйте заменить

for($i = 0;$i<=$venue_count; $i++){

на

for($i = 0;$i<$venue_count; $i++){

Не забывайте, что индексы массива начинаются с 0, поэтому последний элемент в массиве всегда count($array) - 1

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...