Welcome Guest, Not a member yet? Register   Sign In
Getting SQL Results Urgent
#1
Exclamation 

Hello, First Off Im New To CodeIgniter, And Also To PHP a bit.

Anyways I am creating a widget, but i need to get some variables based off the ID of the widget and Owners ID.

Builder.php - Model
Code:
function insertresponsive($data)
   {
       return $this->db->insert('users_widgets', $data);
   }

Widget_Builder.php - Controller

Quote:function build_thumbnail_responsive()
    {
 if($this->session->userdata('logged_in'))
   {

  
        //set validation rules
        $this->form_validation->set_rules('Name', 'Name', 'required|xss_clean|min_length[3]|max_length[30]');
$this->form_validation->set_rules('Website', 'Website', 'required|xss_clean|min_length[5]|max_length[30]|callback_Website_check');
        $this->form_validation->set_rules('Style', 'Radio Button', 'required|is_natural|xss_clean|callback_style_check');
$this->form_validation->set_rules('Layout', 'Radio Button', 'required|is_natural|xss_clean|callback_layout_check');
$this->form_validation->set_rules('Mlayout', 'Radio Button', 'required|is_natural|xss_clean|callback_Mlayout_check');
        $this->form_validation->set_rules('SelectHeader', 'Select Header', 'required|is_natural|xss_clean|callback_Header_check');
        $this->form_validation->set_rules('SelectTitle', 'Select Title', 'required|is_natural|xss_clean|callback_SelectTitle_check');
       
        
        //validate form input
        if ($this->form_validation->run() == FALSE)
        {
            // fails
 $session_data = $this->session->userdata('logged_in');
     $data['username'] = $session_data['username'];
     $this->load->view('widget_builder_view', $data);       }
        else
        {
$session_data = $this->session->userdata('logged_in');
$Wid = random_string('alnum', 25);
            //insert the user registration details into database
            $data = array(
'Userid' => $session_data['id'],
'enabled_stylesheet' => $this->input->post('Style').$this->input->post('Layout').$this->input->post('Mlayout'),
'id' => $Wid,
'Website' => $this->input->post('Website'),
                'Name' => $this->input->post('Name'),
                'Titlechar' => $this->input->post('SelectTitle'),
                'Headertext' => $this->input->post('SelectHeader'),
                'Type' => $this->input->post('Style'),
                'Createddate' => $my_date = date("Y-m-d", time())
            );
            
            // insert form data into database
            if ($this->builder->insertresponsive($data))
            {
                $this->session->set_flashdata('msg','<div class="alert alert-danger text-center">Oops! Error.  Please try again later!!!</div>');

                redirect('widget_install/?id='.$Wid);
            }
            else
            {

After they submit the widget settings, it then inserts it into the database. It then loads widget_install controller and attaches the Widget ID to it. But what should be in the Widget_Install controller to get MYSQL records, I also Need to send the 'Userid' => $session_data['id'] some how so i can Check For Both ID and User ID .
Reply
#2

Cleaned Up Code A Bit

Code:
function build_thumbnail_responsive()
   {

 
       //set validation rules
       $this->form_validation->set_rules('Name', 'Name', 'required|xss_clean|min_length[3]|max_length[30]');
    $this->form_validation->set_rules('Website', 'Website', 'required|xss_clean|min_length[5]|max_length[30]|callback_Website_check');
       $this->form_validation->set_rules('Style', 'Radio Button', 'required|is_natural|xss_clean|callback_style_check');
    $this->form_validation->set_rules('Layout', 'Radio Button', 'required|is_natural|xss_clean|callback_layout_check');
    $this->form_validation->set_rules('Mlayout', 'Radio Button', 'required|is_natural|xss_clean|callback_Mlayout_check');
       $this->form_validation->set_rules('SelectHeader', 'Select Header', 'required|is_natural|xss_clean|callback_Header_check');
       $this->form_validation->set_rules('SelectTitle', 'Select Title', 'required|is_natural|xss_clean|callback_SelectTitle_check');
     
       
       //validate form input
       if ($this->form_validation->run() == FALSE)
       {
           // fails
    $this->load->view('widget_builder_view');       }
       else
       {
$session_data = $this->session->userdata('logged_in');
$Wid = random_string('alnum', 25);
           //insert the user registration details into database
           $data = array(
            'Userid' => $session_data['id'],
                'enabled_stylesheet' => $this->input->post('Style').$this->input->post('Layout').$this->input->post('Mlayout'),
                'id' => $Wid,
                'Website' => $this->input->post('Website'),
               'Name' => $this->input->post('Name'),
               'Titlechar' => $this->input->post('SelectTitle'),
               'Headertext' => $this->input->post('SelectHeader'),
               'Type' => $this->input->post('Style'),
               'Createddate' => $my_date = date("Y-m-d", time())
           );
           
           // insert form data into database
           if ($this->builder->insertresponsive($data))
           {
               $this->session->set_flashdata('msg','<div class="alert alert-danger text-center">Oops! Error.  Please try again later!!!</div>');

               redirect('widget_install/?id='.$Wid);
           }
           else
           {
               // error
               $this->session->set_flashdata('msg','<div class="alert alert-danger text-center">Oops! Error.  Please try again later!!!</div>');
               redirect('user/register');
           }
       }
 
}
Reply




Theme © iAndrew 2016 - Forum software by © MyBB