Jump to content

All records are INSERTED... I only want one!


Red2034

Recommended Posts

So, I am displaying a masterList table of all my records and using a btn in each row to try to INSERT only that row into another table. Here what I have so far:

 <?php  $classes = $this->db->get('class')->result_array();?>
 <?php $classesMaster = $this->db->get('class_master')->result_array();
 foreach($classesMaster as $row):?>
 <tr>
 <td width="50" align="center">
 <a href="index.php" onclick="<?php $data['title'] = $row['title'];
                                    $data['enroll_date'] = date("Y-m-d");
                                    $this->db->insert('class', $data);?>"  >
                                    <?php echo get_phrase('enroll');?>
                                    </a>
                            </td>...

everytime I launch the page it INSERTs all the records from my masterList into the other table... Do you see my mistake?

 

Thanks in advance!

PHP is server side.  It has no idea about buttons, javascript, forms, etc.  All it knows is that you are telling it to insert the data in the foreach loop, which would insert each line as it processes them.

 

What you would have to do, is create a second script, and pass the info to it via a POST.  This can be done by a form with hidden values and a submit button, or a submit button that sends it via javascript (AJAX).

You would really only need to send the row ID to the second page, as you can do everything inside of the database with an INSERT...SELECT statement.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.