<?php
class Subject
{
    public $connLink;
    function __construct($url="../manage/connection.php")
    {
        $this->connLink=$url;
    }

    function addSubject($name,$added_by)
    {
        include $this->connLink;

        $add=$connect->query("INSERT INTO subject (name, added_by)
        VALUES('$name', '$added_by')");
        if($add)
        {
            return true;
        }
        else
        {
            return false;
        }
    }

    function getSubject($id)
    {
        include $this->connLink;
        $getT=$connect->query("SELECT * FROM subject WHERE id='$id'")->fetch_assoc();
        return $getT;
    }

    function getAllSubjects()
    {
        include $this->connLink;
        $subjects=array();
        $getS=$connect->query("SELECT * FROM subject");
        while($subject=$getS->fetch_assoc())
        {
            array_push($subjects, $subject);
        }
        return $subjects;
    } 
    function findSubject($name)
    {
        include $this->connLink;
        $getT=$connect->query("SELECT * FROM subject WHERE name='$name'");
        if($getT->num_rows!=0)
        {
            return true;
        }
        else
        {
            return false;
        }
    } 
    function updateSubject($name, $subject_id)
    {
        include $this->connLink;
        $update=$connect->query("UPDATE subject SET name='$name' WHERE id='$subject_id'");
        return $update;
        
    }
}
?>