OK, please before slamming me guys know that I have been studying and studying and am new to PHP OOP/MVC. I am really trying to learn and learn the right way from the start.
My current code is as follows and it WORKS. I just want to know if this is proper formatting to fall in line with MVC standards. Unfortunately I was able to find stuff for a single query on a MySQL database but when it comes to performing multiple record query's I cannot find any good information.
For that reason I thought this question would not only be helpful to me but to others like me in the future. So without further ado here is my code:
Main Page:
$job_controller = new job_controller();
$job_model = new job_model();
$job_view = new job_view();
$job_model->get_jobs();
$job_controller->job_query($country, $job_model->jobStatus, $job_model->skill1, $job_model->skill2, $job_model->skill3, $job_model->skill4, $job_model->skill5);
Job Classes:
class job_model extends job_controller{
public $skills;
public $skillarray;
public $skill1;
public $skill2;
public $skill3;
public $skill4;
public $skill5;
public $jobStatus;
public function get_jobs(){
$this->skills = 'web';
$this->skillarray= explode(',', $this->skills);
$this->skill1 = $this->skillarray[0];
$this->skill2 = $this->skillarray[1];
$this->skill3 = $this->skillarray[2];
$this->skill4 = $this->skillarray[3];
$this->skill5 = $this->skillarray[4];
$this->jobStatus = 1;
}
}
class job_view extends job_controller{
public function set_jobs($jobid, $jobname, $jobDescription, $jobCategory, $jobTags, $jobStatus, $jobOwner, $jobOwnerName, $jobWorkerName, $jobState, $jobCountry){
$this->jobid = $jobid;
$this->jobname = $jobname;
$this->jobDescription = $jobDescription;
$this->jobCategory = $jobCategory;
$this->jobTags = $jobTags;
$this->jobStatus = $jobStatus;
$this->jobOwner = $jobOwner;
$this->jobOwnerName = $jobOwnerName;
$this->jobWorkerName = $jobWorkerName;
$this->jobState = $jobState;
$this->jobCountry = $jobCountry;
echo '<p><strong><a href="../jobs/view_job.php?jobID='.$this->jobid.'">' . $this->jobname . '</a></strong><br>'
. $this->jobDescription . '<br>'
. $this->jobOwnerName . '<br></p>';
}
}
DB Classes:
class job_controller extends dbconnect{
public function job_query($country, $jobStatus, $skill1, $skill2, $skill3, $skill4, $skill5){
$this->country = $country;
$this->jobStatus = $jobStatus;
$this->skill1 = $skill1;
$this->skill2 = $skill2;
$this->skill3 = $skill3;
$this->skill4 = $skill4;
$this->skill5 = $skill5;
echo $this->country . $this->jobStatus . $this->skill1;
$jq = $this->con()->prepare("SELECT jobID, jobName, jobDescription, jobCategory, jobTags, jobStatus, jobOwner, job_owner_name, job_worker_name, jobState, jobCountry FROM jobs WHERE jobCountry=? AND jobStatus=? AND jobCategory LIKE ? OR jobcategory LIKE ? OR jobcategory LIKE ? OR jobcategory LIKE ? OR jobcategory LIKE ? ORDER BY jobID");
$jq-> bind_param('sisssss', $this->country, $this->jobStatus, $this->skill1, $this->skill2, $this->skill3, $this->skill4, $this->skill5);
$jq-> execute();
$jq-> bind_result($jobid, $jobname, $jobDescription, $jobCategory, $jobTags, $jobStatus, $jobOwner, $jobOwnerName, $jobWorkerName, $jobState, $jobCountry);
while($jq->fetch()){
$job_view = new job_view();
echo $job_view->set_jobs($jobid, $jobname, $jobDescription, $jobCategory, $jobTags, $jobStatus, $jobOwner, $jobOwnerName, $jobWorkerName, $jobState, $jobCountry);
}
}
}
If this is not proper please let me know what I could do to change it. I know that using a framework is best but this is for school and that is not an option. Thanks in advance for any help :)