What's new

Closed pa help mga master

Status
Not open for further replies.

MhaShziYing

Eternal Poster
Joined
Mar 3, 2019
Posts
516
Reaction
1,967
Points
379
Age
32
Untitled.png


Everytime na nag add ako hindi sya nag uupdate dun sa database
 

Attachments

<?php
include('include/header.php');
include('include/sidebar.php');
include('data/class_model.php');

$search = isset($_POST['search']) ? $_POST['search']: null;
$class = $class->getclass($search);
?>
<div id="page-wrapper">

<div class="container-fluid">

<!-- Page Heading -->
<div class="row">
<div class="col-lg-12">
<h1 class="page-header">
<small>CLASS INFORMATION</small>
</h1>
<ol class="breadcrumb">
<li>
<i class="fa fa-dashboard"></i> <a href="index.php">Dashboard</a>
</li>
<li class="active">
Class
</li>
</ol>
</div>
</div>
<!-- /.row -->
<div class="row">
<div class="col-lg-12">
<div class="form-inline form-padding">
<form action="class.php" method="post">
<input type="text" class="form-control" name="search" placeholder="Search Class Info...">
<button type="submit" name="submitsearch" class="btn btn-success"><i class="fa fa-search"></i> Search</button>
<button type="button" class="btn btn-primary" data-toggle="modal" data-target="#addclass">Add Class</button>
</form>
</div>
</div>
</div>
<!--/.row -->
<hr />
<div class="row">
<div class="col-lg-12">
<?php if(isset($_GET['r'])): ?>
<?php
$r = $_GET['r'];
if($r=='added'){
$classs='success';
}else if($r=='updated'){
$classs='info';
}else if($r=='deleted'){
$classs='danger';
}else{
$classs='hide';
}
?>
<div class="alert alert-<?php echo $classs?> <?php echo $classs; ?>">
<strong>Class info successfully <?php echo $r; ?>!</strong>
</div>
<?php endif; ?>
</div>
</div>
<div class="row">
<div class="col-lg-12">

<div class="table-responsive">
<table class="table table-striped">
<thead>
<tr>
<th>#</th>
<th>Subject</th>
<th>Class Name</th>
<th class="text-center">Semester</th>
<th class="text-center">S.Y.</th>
<th class="text-center">Teacher</th>
<th class="text-center">Students</th>
<th class="text-center">Action</th>
</tr>
</thead>
<tbody>
<?php $c = 1; ?>
<?php while($row = mysql_fetch_array($class)): ?>
<tr>
<td><?php echo $c;?></td>
<td><?php echo $row['subject'];?></td>
<td><?php echo $row['course'].' '.$row['year'].' - '.$row['section'];?></td>
<td class="text-center"><?php echo $row['sem'];?></td>
<td class="text-center"><?php echo $row['SY'];?></td>
<td class="text-center"><a href="classteacher.php?classid=<?php echo $row['id'];?>&teacherid=<?php echo $row['teacher'];?>" title="update teacher">View</a></td>
<td class="text-center"><a href="classstudent.php?classid=<?php echo $row['id'];?>" title="update students" title="add student">View</a></td>
<td class="text-center">
<a href="edit.php?type=class&id=<?php echo $row['id']?>" title="update class"><i class="fa fa-edit fa-2x text-primary"></i></a>
<a href="data/data_model.php?q=delete&table=class&id=<?php echo $row['id']?>" title="delete class"><i class="fa fa-times-circle fa-2x text-danger confirmation"></i></a></td>
</tr>
<?php $c++; ?>
<?php endwhile; ?>
<?php if(mysql_num_rows($class) < 1): ?>
<tr>
<td colspan="7" class="bg-danger text-danger text-center">* EMPTY *</td>
</tr>
<?php endif; ?>
</tbody>
</table>
</div>
</div>
</div>

</div>
<!-- /.container-fluid -->

</div>
<!-- /#page-wrapper -->
<?php include('include/modal.php'); ?>
<?php include('include/footer.php'); ?>


<?php

$class = new Dataclass();
if(isset($_GET['q'])){
$class->$_GET['q']();
}
class Dataclass {

function __construct(){
if(!isset($_SESSION['id'])){
header('location:../../');
}
}

//create logs
function logs($act){
$date = date('m-d-Y h:i:s A');
echo $q = "insert into log values(null,'$date','$act')";
mysql_query($q);
return true;
}

//get all class info
function getclass($search){
$q = "select * from class where course like '%$search%' or year like '%$search%' or section like '%$search%' or sem like '%$search%' or subject like '%$search%' order by course,year,section,sem asc";
$r = mysql_query($q);

return $r;
}

//get class by ID
function getclassbyid($id){
$q = "select * from class where id=$id";
$r = mysql_query($q);

return $r;
}
//add class
function addclass(){
include('../../config.php');
$course = $_POST['course'];
$year = $_POST['year'];
$section = $_POST['section'];
$sem = $_POST['sem'];
$subject = $_POST['subject'];
$sy = $_POST['sy'];

echo $q = "insert into class values('','$course','$year','$section','$sem','','$subject','$sy')";
mysql_query($q);
$act = "create new class $course $year - $section with the subject of $subject";
$this->logs($act);
header('location:../class.php?r=added');
}

//update class
function updateclass(){
include('../../config.php');
$id = $_GET['id'];
$course = $_POST['course'];
$year = $_POST['year'];
$section = $_POST['section'];
$sem = $_POST['sem'];
$subject = $_POST['subject'];
$sy = $_POST['sy'];

echo $q = "update class set course='$course', year='$year', section='$section', sem='$sem', subject='$subject', SY='$sy' where id=$id";
mysql_query($q);
$act = "update class $course $year - $section with the subject of $subject";
$this->logs($act);
header('location:../class.php?r=updated');
}

//get all students in that class
function getstudentsubject(){
$classid = $_GET['classid'];
$q = "select * from studentsubject where classid=$classid";
$r = mysql_query($q);
$result = array();
while($row = mysql_fetch_array($r)){
$q2 = 'select * from student where id='.$row['studid'].'';
$r2 = mysql_query($q2);
$result[] = mysql_fetch_array($r2);
}
return $result;
}

//add student to class
function addstudent(){
include('../../config.php');
$classid = $_GET['classid'];
$studid = $_GET['studid'];
$verify = $this->verifystudent($studid,$classid);
if($verify){
echo $q = "INSERT INTO studentsubject (studid,classid) VALUES ('$studid', '$classid');";
mysql_query($q);
header('location:../classstudent.php?r=success&classid='.$classid.'');
}else{
header('location:../classstudent.php?r=duplicate&classid='.$classid.'');
}

$tmp = mysql_query("select * from class where id=$classid");
$tmp_row = mysql_fetch_array($tmp);
$tmp_subject = $tmp_row['subject'];
$tmp_class = $tmp_row['course'].' '.$tmp_row['year'].'-'.$tmp_row['section'];

$tmp = mysql_query("select * from student where id=$studid");
$tmp_row = mysql_fetch_array($tmp);
$tmp_student = $tmp_row['fname'].' '.$tmp_row['lname'];

$act = "add student $tmp_student to class $tmp_class with the subject of $tmp_subject";
$this->logs($act);
}
//verify if he/she is enrolled
function verifystudent($studid,$classid){
include('../../config.php');
$q = "select * from studentsubject where studid=$studid and classid=$classid";
$r = mysql_query($q);
if(mysql_num_rows($r) < 1){
return true;
}else{
return false;
}
}
//remove student to the class
function removestudent(){
$classid = $_GET['classid'];
$studid = $_GET['studid'];
include('../../config.php');
$q = "delete from studentsubject where studid=$studid and classid=$classid";
mysql_query($q);

$tmp = mysql_query("select * from class where id=$classid");
$tmp_row = mysql_fetch_array($tmp);
$tmp_subject = $tmp_row['subject'];
$tmp_class = $tmp_row['course'].' '.$tmp_row['year'].'-'.$tmp_row['section'];

$tmp = mysql_query("select * from student where id=$studid");
$tmp_row = mysql_fetch_array($tmp);
$tmp_student = $tmp_row['fname'].' '.$tmp_row['lname'];

$act = "remove student $tmp_student from class $tmp_class with the subject of $tmp_subject";
$this->logs($act);

header('location:../classstudent.php?r=success&classid='.$classid.'');
}

//update teacher
function updateteacher(){
$classid = $_GET['classid'];
$teachid = $_GET['teachid'];
include('../../config.php');
$q = "update class set teacher=$teachid where id=$classid";
mysql_query($q);

$tmp = mysql_query("select * from class where id=$classid");
$tmp_row = mysql_fetch_array($tmp);
$tmp_subject = $tmp_row['subject'];
$tmp_class = $tmp_row['course'].' '.$tmp_row['year'].'-'.$tmp_row['section'];

$tmp = mysql_query("select * from teacher where id=$teachid");
$tmp_row = mysql_fetch_array($tmp);
$tmp_teacher = $tmp_row['fname'].' '.$tmp_row['lname'];

$act = "assign teacher $tmp_teacher to class $tmp_class with the subject of $tmp_subject";
$this->logs($act);

header('location:../classteacher.php?classid='.$classid.'&teacherid='.$teachid.'');
}

}
?>
 
Status
Not open for further replies.

Similar threads

Back
Top