Welcome Guest, Not a member yet? Register   Sign In
Updating with a Checkbox
#1

[eluser]EvanCalkins[/eluser]
Hello,

I am fairly new to Code Igniter ( and php ) and have a question on a very small application I'm developing for my church.

I am building a small system that allows youth to sign up for camp online, and record those registrants into a database. I am then creating a simple back-end for the church admin to view all the registrants and update their record if they have paid.

Currently, I have all the records being pulled from the database and spit out into a simple table. I need the ability for a church admin to go into this a check a checkbox if the registrant has paid, and on submit, the database would update the 'paid' field.

Would someone care to give me an idea of what this action would look like?
#2

[eluser]Kotzilla[/eluser]
i used array checkbox like
<input type="checkbox" name="item[]" value="<?php echo $itemvalue; ?>" />

when you submit data $_POST['item'] will be in Array so all i have to do is

if(is_array($_POST['item']) && count($_POST['item']) >= 1)
{
for($i=0;$i<count($_POST['item']);$i++)
{
/* SQL statement like ' update table set item='$_POST['item'][$i]' where id='$id'; '
}
}

=)
#3

[eluser]EvanCalkins[/eluser]
Great! I'll give this a go.
#4

[eluser]Phil Sturgeon[/eluser]
That would be to update payments for multiple items. We only need a single check box to show this.

Add a field called 'paid_date' to the database type of Integer and 11 digits long.

Get the data from the user and output to page.

Code:
&lt;?php
class Controller {

function edit($id) {

$data['user'] = $this->user_model->get($id);

if($this->input->post('has_paid')) {
  // Update the user with the date they paid
  $this->user_model->paid($id);
}

$this->load->view('something', $data);

}

}?&gt;

In your form view, add:

Code:
&lt;?=form_open('controller');?&gt;
Has Paid? &lt;?=form_checkbox('has_paid', TRUE, !empty($user->has_paid));?&gt;

The model would be

Code:
&lt;?php

class user_model {

  function get($id) {
    $query = $this->db->getwhere('users', array('id' => $id));
    return $query->row();
  }

  function paid($id) {
    $this->load->helper('date');    
  
    return $this->db->update('users', array('paid_date' => now()));
  }

}
?&gt;


That is a very rough outline, a few steps up from pseudo code. Hope it helps.
#5

[eluser]Kotzilla[/eluser]
Thank's for sharing pyromaniac
That's great idea Wink




Theme © iAndrew 2016 - Forum software by © MyBB