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!

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.