[eluser]raindahl[/eluser]
Hi there I am looking for some help for my Quiz Application that I have begun creating for a University project
here
It basically is a CMS for creating Quiz content I have everything working such as updating the Database questions etc
But my problem is that when I create a new user and they login it still shows the same Data for every new user I create how would I sort this so each user has their own seperate questions and answers ?
My Database tables are this :
CREATE TABLE IF NOT EXISTS `user` (
`id` int(50) NOT NULL AUTO_INCREMENT,
`username` varchar(50) NOT NULL,
`email` varchar(100) NOT NULL,
`password` varchar(255) NOT NULL,
'quiz_no' int(3) NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=2 ;
The user table is for users to create their accounts etc
CREATE TABLE IF NOT EXISTS `quiz` (
`no` int(3) NOT NULL AUTO_INCREMENT,
`writing` varchar(100) NOT NULL,
`opt1` varchar(50) NOT NULL,
`opt2` varchar(50) NOT NULL,
`opt3` varchar(50) NOT NULL,
`opt4` varchar(50) NOT NULL,
`answer` varchar(4) NOT NULL,
PRIMARY KEY (`no`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=12 ;
quiz is for each individual question
CREATE TABLE IF NOT EXISTS `student` (
`id_user` int(3) NOT NULL AUTO_INCREMENT,
`name` varchar(30) NOT NULL,
`id_question_type` int(3) NOT NULL,
`grade` int(3) NOT NULL,
`date_test` varchar(40) NOT NULL,
`minutes` int(10) NOT NULL,
`seconds` int(10) NOT NULL,
PRIMARY KEY (`id_user`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=287 ;
student is for the people taking the quizzes
I was then told to have a connecting table which is :
CREATE TABLE IF NOT EXISTS 'pairs'
('id' int(50) NOT NULL AUTO_INCREMENT, 'user_id' int(50), 'quiz_no' int(3),PRIMARY KEY ('id'))
ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=2;
I now have added the SQL code that the guys below have mentioned but I am not sure which PHP code to put in to get it all connected? It will be for these models :
Here is the Main_Model :
Code:
class Main_model extends CI_Model
{
function __construct()
{
parent::__construct();
}
function entry_student($xname,)
{
$query="insert into student (name,) values ('$xname','$xgrade_id_max')";
$run_query=$this->db->query("$query");
return $run_query;
}
function show_quiz()
{
$query="select * from quiz order by no";
$outcome=$this->db->query($query);
return $outcome;
}
function record_entry_quiz()
{
$make_quiz="Select * from quiz";
$outcome=$this->db->query("$make_quiz");
$jml_quiz=$outcome->num_rows();
if ($jml_quiz==0)
{ $jml_quizs=1; }
else
{ $jml_quizs=$jml_quiz+1; }
$xquiz=$this->input->post('vquiz');
$xansweran1=$this->input->post('vansweran1');
$xansweran2=$this->input->post('vansweran2');
$xansweran3=$this->input->post('vansweran3');
$xansweran4=$this->input->post('vansweran4');
$xradio=$this->input->post('vradio');
$query="insert into quiz (no,writing,opt1,opt2,opt3,opt4,answer) values ('$jml_quizs','$xquiz','$xansweran1','$xansweran2','$xansweran3','$xansweran4','$xradio')";
$outcome_query=$this->db->query("$query");
return $outcome_query;
}
function edit_quiz()
{
$pressed=$this->uri->segment(3);
$xquiz=$this->input->post('vquiz');
$xansweran1=$this->input->post('vansweran1');
$xansweran2=$this->input->post('vansweran2');
$xansweran3=$this->input->post('vansweran3');
$xansweran4=$this->input->post('vansweran4');
$xradio=$this->input->post('vradio');
$query="update quiz set writing='$xquiz',opt1='$xansweran1',opt2='$xansweran2',opt3='$xansweran3',opt4='$xansweran4',
answer='$xradio' where no='$pressed'";
$outcome_query=$this->db->query("$query");
return $outcome_query;
}
function delete_quiz()
{
$pressed=$this->uri->segment(3);
$scriptdel="delete from quiz where no='$pressed' ";
$outcome_edit=$this->db->query("$scriptdel");
return $outcome_edit;
}
function delete_user()
{
$pressed=$this->uri->segment(3);
$scriptdel="delete from user where id='$pressed' ";
$outcome_edit=$this->db->query("$scriptdel");
return $outcome_edit;
}
function view_data()
{
$pressed=$this->uri->segment(3);
$scriptview="select * from quiz where no='$pressed'";
$outcome=$this->db->query("$scriptview");
return $outcome;
}
function edit_data()
{
$pressed=$this->uri->segment(3);
$scriptedit="select * from quiz where no='$pressed'";
$outcome=$this->db->query("$scriptedit");
return $outcome;
}
function login_admin()
{
$xusername= mysql_real_escape_string($this->input->post('vusername'));
$xpassword=md5(mysql_real_escape_string($this->input->post('vpassword')));
$query="select * from admin where username='$xusername' and password='$xpassword'";
$wayquery=$this->db->query("$query");
return $wayquery;
}
function update_passwd_admin()
{
$zpassword=$this->input->post('vpassword');
$xpassword=md5($zpassword);
$query="update admin set passw