[База данных: multi_login, Таблица: викторина Поля: quizID, вопрос, choice1, choice2, choice3, ответ, тема]
Мой тест работает отлично, я просто хочу иметь возможность удалить тест (которыйбудет сделано за пределами ввода страницы php викторины), когда на странице викторины, удастся удалить ответы (выбор 1, выбор 2, выбор 3 или ответ) и вопросы (вопрос).
Модель:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class quizmodel extends CI_Model {
public function getQuestions()
{
$this->db->select("quizID, question, choice1, choice2, choice3, answer, subject");
$this->db->from("quiz");
$this->db->where("subject",'computing');
$query = $this->db->get();
return $query->result();
$num_data_returned = $query->num_rows;
if ($num_data_returned < 1) {
echo "There is no data in the database";
exit();
}
}
}
Контроллер:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Questions extends CI_Controller {
function __construct() {
parent::__construct();
$this->load->database();
}
public function quizdisplay()
{
$this->load->model('quizmodel');
$this->data['questions'] = $this->quizmodel->getQuestions();
$this->load->view('play_quiz', $this->data);
}
public function resultdisplay()
{
$this->data['checks'] = array(
'ques1' => $this->input->post('quizid1'),
'ques2' => $this->input->post('quizid2'),
'ques3' => $this->input->post('quizid3'),
'ques4' => $this->input->post('quizid4'),
'ques5' => $this->input->post('quizid5'),
'ques6' => $this->input->post('quizid6'),
'ques7' => $this->input->post('quizid7'),
'ques8' => $this->input->post('quizid8'),
'ques9' => $this->input->post('quizid9'),
'ques10' => $this->input->post('quizid10'),
);
$this->load->model('quizmodel');
$this->data['results'] = $this->quizmodel->getQuestions();
$this->load->view('result_display', $this->data);
}
}
Просмотр для игры Викторина:
<div id="container">
<h1>Play the Computing Quiz!</h1>
<form method="post" action="<?php echo base_url();?>index.php/Questions/resultdisplay">
<?php foreach($questions as $row) { ?>
<?php $ans_array = array($row->choice1, $row->choice2, $row->choice3, $row->answer);
shuffle($ans_array); ?>
<p><?=$row->question?></p>
<input type="radio" name="quizid<?=$row->quizID?>" value="<?=$ans_array[0]?>" required> <?=$ans_array[0]?><br>
<input type="radio" name="quizid<?=$row->quizID?>" value="<?=$ans_array[1]?>"> <?=$ans_array[1]?><br>
<input type="radio" name="quizid<?=$row->quizID?>" value="<?=$ans_array[2]?>"> <?=$ans_array[2]?><br>
<input type="radio" name="quizid<?=$row->quizID?>" value="<?=$ans_array[3]?>"> <?=$ans_array[3]?><br>
<?php } ?>
<br><br>
<input type="submit" value="Submit!">
</form>
</div><div id="container">
<h1>Play the Computing Quiz!</h1>
<form method="post" action="<?php echo base_url();?>index.php/Questions/resultdisplay">
<?php foreach($questions as $row) { ?>
<?php $ans_array = array($row->choice1, $row->choice2, $row->choice3, $row->answer);
shuffle($ans_array); ?>
<p><?=$row->question?></p>
<input type="radio" name="quizid<?=$row->quizID?>" value="<?=$ans_array[0]?>" required> <?=$ans_array[0]?><br>
<input type="radio" name="quizid<?=$row->quizID?>" value="<?=$ans_array[1]?>"> <?=$ans_array[1]?><br>
<input type="radio" name="quizid<?=$row->quizID?>" value="<?=$ans_array[2]?>"> <?=$ans_array[2]?><br>
<input type="radio" name="quizid<?=$row->quizID?>" value="<?=$ans_array[3]?>"> <?=$ans_array[3]?><br>
<?php } ?>
<br><br>
<input type="submit" value="Submit!">
</form>
</div>
ПОЖАЛУЙСТА, ПОМОГИТЕ!