У меня возникли проблемы с кодированием для редактирования/удаления вопроса в базе данных. Из моих вопросов викторины. Это моя модель. Я хотел бы отредактировать вопрос из представления через контроллер.codeigniter: редактирование и удаление из базы данных
Это мой текущий режим:
function getquestions($quizid)
{
// get data about the quiz - we need the quiz size
$quiz = $this->getquiz($quizid);
$qzsize = $quiz['quizsize'];
$this->db->select('id'); // we want just the id fields
$this->db->limit($qzsize); // how many questions to ask
// this next clause allows us to select random questions - a full discussion of how this works and its drawbacks is
// here https://www.warpconduit.net/2011/03/23/selecting-a-random-record-using-mysql-benchmark-results/
$this->db->order_by('RAND()');
$res = $this->db->get_where('questions',array('quizid' => $quizid));
log_message('DEBUG',$this->db->last_query());
if ($res->num_rows() == 0) {
// no questions found!
// returning false to controller tells it we have encountered an error
// leave controller to decide how to handle error
return false;
}
$questions = array();
foreach ($res->result_array() as $row) {
$questions[] = $row['id'];
}
shuffle($questions); // provide questions in random order
$res->free_result();
return $questions;
}
/**
* get a question
* @param int - question id
* @return mixed false|array - question data + answers (array)
*/
function getquestion($id) {
$this->db->where('id',$id);
$res = $this->db->get('questions');
if ($res->num_rows() != 1) {
return false;
}
$question = $res->row_array(); // get first row as an array - this is the question data
// now get the answers for this question
$res = $this->db->get_where('answers',array('questionid' => $id));
if ($res->num_rows() < 2) {
// must have at least two answers
return false;
}
$answers = array();
// get each row as an array and push it onto the answers array
foreach ($res->result_array() as $row) {
$answers[] = $row;
}
shuffle($answers);
// now return all the data as one array, with keys to help access elements
return array('q' => $question,'a' => $answers);
}
после просмотра и контроллер тоже. Только релевантные коды –
Мне нужна помощь только с моделью. Представление было бы формой –