Welcome Guest, Not a member yet? Register   Sign In
code flow; how would you structure this in CI?

[eluser]Dave Rau[/eluser]
So I've got two tables with some data; one has some contact info and another is an application for a grant. I'd like to set something up that's similar to scaffolding, but with more refined control over dropdowns, textarea sizes, multi-columns, etc. The straight up scaffolding just doesn't cut it for my needs.

So what's the best way to setup a view and controller for this? One view with a table join to display the data, then how would the controller handle the data? How do I know which fields belong to which update? How have you handled this before?

I'm just looking for some starting points, I feel pretty good about the code, but I'm kind of stuck on the concepts right now.


By example, first read all informations(contact_info and application) of an user
function info($id)
$query = $this->db->query("SELECT Ci.*, App.*
FROM contact_info Ci , application App
WHERE Ci.some_id=$id AND App.some_id=$id AND App.id=Ci.id");
if ($query->num_rows() > 0)
  return $query->row_array();
  return FALSE;

Pass it to your view and when submitted run update operation
  //Update contact_info table by user_address and user_contact_no

  //Update application table by apply_date and apply_for
$data['user_info'] = $this->your_model_name->info($id);

Partial of your view
<?php if(count($user_info)>0) {?>
      <input type="text" name="user_address" value="<?=$row['user_address'];?>">
      <input type="text" name="user_contact_no" value="<?=$row['user_contact_no'];?>">
      <input type="text" name="apply_date" value="<?=$row['apply_date'];?>">
      <input type="text" name="apply_for" value="<?=$row['apply_for'];?>">
      <input type="submit" name="submit" value="Update info">

[eluser]Dave Rau[/eluser]
Hi Sumon,

I follow all of that, I was concerned about when my view includes info from a second table in the database. One HTML form, two sets of data from two different tables. How can I smartly handle the updating of the database based on that scenario?

One person can have many applications, so this provides a way for them to update their contact info at the top of the page and their application below, all in one shot. It seems like that complicates things, but maybe not. What are your thoughts?

I don't think it's too complicated. Lets say we first read all contact info of an user(single row) and applications (multiple row). Now in view lets create an area where we display contact informations and another portion about multiple applications. Moreover, contact info is easy one so it's simple. Display multiple application in such a way that all controls(text boxes, text areas, drop down)are defined as array. i.e
<input type="text" name="user_address" value="<?=$contact_info['user_address'];?>">
      <input type="text" name="user_contact_no" value="<?=$contact_info['user_contact_no'];?>">
<?php if(count($appliation_info)>0) {?>
<?php foreach($appliation_info as $row):?>    
      <input type="text" name="apply_id[]" value="<?=$row['apply_id'];?>">
      <input type="text" name="apply_date[]" value="<?=$row['apply_date'];?>">
      <input type="text" name="apply_for[]" value="<?=$row['apply_for'];?>">
      <input type="submit" name="submit" value="Update info">
<?php endforeach; ?>
<?php }?>
Now lets read array values(apply_date and apply_for) and update for every records using apply_id per record(not all informations in a single update query).
sorry for my english Wink

Theme © iAndrew 2016 - Forum software by © MyBB