Codeigniter--How do store info? (noob)
I'm building my first real CI app. I have to build a survey system--If the specifics are important, I'll elaborate.
What is the best way to post the info to the db from the user? In a single row, comma separated? I'm a noob here, so detail would be appreciated! :)
I should add: the user needs to have the ability to try multiple times for the test and have each test's score charted. Payment is required to take each test.
Here's where I'm at. This code works, but I'm sure there's a more elegant way to do things.
$this->db->select('credits')->from('be_user_profiles')->where('user_id', $this->session->userdata('id'));
$query = $this->db->get(开发者_高级运维);
foreach ($query->result() as $row)
{
echo $row->credits;
}
What about this?
That's more like a code organization / code structure question than a problem.
You can fetch your input data "by hand" or use Active Record CI library to do that (https://www.codeigniter.com/userguide2/database/active_record.html#insert)
If CI has ORM implemented, the job should be even easier than this.
Just create a controller and check the input data on it (or inside the model) and create a model to apply the necessary cleanups, data verification and proper data assign to one or mode tables and you're set.
edit : more elegant than the example you've showed would be with ORM, but I'm not sure CI has that implemented yet.
It depends on how the data is structured, but your best bet would be to have a survey table, and store the answer to each question in a different column.
From an MVC point of view, you would have a form in a view, have the controller pass the data from that form the model when it is submitted, then have the model clean the data and insert it into the database.
精彩评论