Welcome Guest, Not a member yet? Register   Sign In
Copy data from one table and insert to another
#1

[eluser]red2034[/eluser]
Hello all! my first post excitement...

on a page in my views folder I have this code that is displaying all my classes available in 'class_master'

Code:
<?php $classesMaster = $this->db->get('class_master')->result_array();
       foreach($classesMaster as $row):?>
                        
                        <tr><td width="50" align="center">    
              <a href="&lt;?php echo base_url();?&gt;index.php?student/classes/enroll/&lt;?php echo        $row['class_id'];?&gt;"  class="btn btn-gray btn-small">
                       &lt;?php echo get_phrase('enroll');?&gt;</a></td>

then on my controller php I have this function:

Code:
function classes($param1 = '', $param2 = '', $classesMaster = '')
    {    
    if ($param1 == 'enroll') {
  
       $class_info = $this->db->get_where('class_master' , array('class_id' => $param2));
      $data['class_id'] = $param2;
         $data['title'] = $class_info['title'];
                $this->db->insert('class', $data);
    redirect(base_url() . 'index.php?student/classes/', 'refresh');
     }

if I delete the $data['title'] = line it works fine by inserting the correct 'class_id' so I know everything is connected right, but as is after clicking the btn on the views page I am getting a blank white php page and the data has not been inserted into 'class'

can anybody see the reason why??? again excited to find this forum!
#2

[eluser]CroNiX[/eluser]
Do you have debug and db_debug enabled?

You should post the schemas to those 2 tables. If it works by removing 'title' then I assume that the 'class' table doesn't have a 'title' field.

It might be blank because of your redirect. You're redirecting to just 'classes' with no parameters, and your $param1 check in classes() says if it is 'enroll', do this, else do nothing.
#3

[eluser]red2034[/eluser]
Thanks for the reply! I should have also mentioned that if I have this code it works as well also:

$data['title'] = 'add title';

so my 'class' table is adding the title section correctly - just not when I try to get the VAR and set it...


not sure how to enable debug or db_debug... so I guess ill google that real quick and see if i can debug it...
#4

[eluser]CroNiX[/eluser]
Ah, yes, because you never grab the result set after executing the query.

Code:
$class_info = $this->db->get_where('class_master' , array('class_id' => $param2))->row_array();//assuming there is only 1 row returned for this query
#5

[eluser]red2034[/eluser]
thank you!
#6

[eluser]red2034[/eluser]


I also wanted to access multiple DBS and found out how. So now that I have access to multiple DBs (default, platform) this is what I would like to do:


Code:
public function index()
    {
  $course_id = '18896';
        if ($this->session->userdata('student_login') != 1)
            redirect(base_url() . 'index.php?login', 'refresh');
        if ($this->session->userdata('student_login') == 1)
$this->db_platform = $this->CI->load->database('platform', TRUE);  
$class_status = $this->db_platform->get_where('class' , array('status' => 'not attempted'))->row_array();
     $data['status'] = 'in-progress';
            
            $this->db_platform->update('status', $data);
   redirect(base_url() . 'index.php?student/dashboard', 'refresh');
  
    }
I am trying to change the ‘status’ data to ‘in-progress’ but it is not updating…

Anybody see my error?
#7

[eluser]CroNiX[/eluser]
Does your status table only contain one entry? Because there is no WHERE on your update.
#8

[eluser]red2034[/eluser]
Actually I'm not able to get my anchor to work...

Code:
<a href="&lt;?php echo base_url();?&gt;index.php?student/classes/launch/&lt;?php echo $row['class_id'] . '/' . $row['deep_link'];?&gt;" class="btn btn-gray btn-small">
                                    &lt;?php echo get_phrase('launch');?&gt;
                                    </a>

Code:
if ($param1 == 'launch') {
       $class_info = $this->db->get_where('class' , array('class_id' => $param2))->row_array();
       $data['status'] = 'in-progress';
       $this->db->where('class_id', $param2);
       $this->db->update('class', $data);
    $class_link = $param3;

   anchor($class_link, 'title="title"', array('target' => '_blank', 'class' => 'new_window'));
     }
#9

[eluser]CroNiX[/eluser]
outputting anchors (links) belong in a view and not in the controller. Also, you have to echo it.




Theme © iAndrew 2016 - Forum software by © MyBB