23. marts 2020 - 23:14
Der er
11 kommentarer
Ingen data udtræk fra database
Når jeg forsøger at trække data fra tabellen subjekt, kommer der ingen data frem. Nogle forslag? Jeg har disse 2 kode: Fra index.php 86) <?php foreach($mysubject as $row): ?> 87) <tr> osv) <td class="text-center"><?php echo $row['subject']; ?></td> <?php $title = $grade->getsubjectitle($conn,$row['subject']);?> <td class="text-center"><?php echo $title[0]['title']; ?></td> <?php $mygrade = $grade->getgrade($conn,$row['id']); ?> <td class="text-center"><?php echo $mygrade['prelim']; ?></td> <td class="text-center"><?php echo $mygrade['midterm']; ?></td> <td class="text-center"><?php echo $mygrade['final']; ?></td> <td class="text-center"><?php echo $mygrade['total']; ?></td> <td class="text-center"><?php echo $mygrade['eqtotal']; ?></td> <!-- <td class="text-center"><?php echo $title[0]['unit']; ?></td>--> </tr> <?php endforeach; ?> Og fra grade.php 21) function getid($conn){ 22) $studid = $_SESSION['id']; osv) $r = mysqli_query($conn,"select * from `student` where studid='$studid'"); $row = mysqli_fetch_array($r, MYSQLI_BOTH); $id = $row['id']; return $id; } function getsubject($conn){ $id = $this->getid($conn); $q = "select * from `studentsubject` where studid='$id'"; $r = mysqli_query($conn,$q); $data = array(); while($row = mysqli_fetch_array($r, MYSQLI_BOTH)){ $classid = $row['classid']; $q2 = "select * from `class` where id='$classid'"; $r2 = mysqli_query($conn,$q2); $data[] = mysqli_fetch_array($r2, MYSQLI_BOTH); } return $data; }
Annonceindlæg fra Computerworld it-jobbank
24. marts 2020 - 07:34
#1
Vi ser ikke nok af koden til at kunne svare dig på det. Du har en funktion der hedder getsubject() der henter dataene, men den bliver aldrig kaldt i det vi ser. Og du udlæser dataene fra en variabel der hedder $mysubject, men den bliver ikke sat her, så vi aner ikke hvad den indeholder. Har du prøvet at var_dump()'e dataene forskellige steder og se præcis hvor de ikke eksisterer første gang?
24. marts 2020 - 08:25
#2
<?php include('../config.php'); $level = isset($_SESSION['level']) ? $_SESSION['level']: null; if($level == null){ header('location:../index.php'); }else if($level != 'student'){ header('location:../'.$level.''); } ?> <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1"> <meta name="description" content=""> <meta name="author" content=""> <link rel="icon" href="favicon.ico"> <title>Online Grading System</title> <!-- Bootstrap core CSS --> <link href="../css/bootstrap.min.css" rel="stylesheet"> <link rel="stylesheet" href="../css/font-awesome.min.css" /> <link rel="stylesheet" href="../css/style.css" /> <link rel="stylesheet" href="mystyle.css" /> </head> <body> <nav class="navbar navbar-inverse navbar-fixed-top" role="navigation"> <div class="container"> <div class="navbar-header"> <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false" aria-controls="navbar"> <span class="sr-only">Toggle navigation</span> <span class="icon-bar"></span> <span class="icon-bar"></span> <span class="icon-bar"></span> </button> <a class="navbar-brand" href="index.php">Online Grading System22</a> </div> <div id="navbar" class="navbar-collapse collapse"> <div class="navbar-form navbar-right"> <label class="text-primary"> Hi, <?php echo $_SESSION['name']; ?> </label> <a href="../logout.php"><button type="button" class="btn btn-success" name="submit">Logout</button></a> <button type="button" class="btn btn-info" data-toggle="modal" data-target="#changepass">Change Password</button> </div> </div><!--/.navbar-collapse --> </div> </nav> <?php include('grade.php'); $mysubject = $grade->getsubject($conn); ?> <div class="container" style="margin-top:60px;"> <!-- Example row of columns --> <div class="row"> <div class="col-lg-12"> <h2 class="text-center">Report of Grades</h2> <div class=""> <table class="table table-bordered"> <thead> <tr class="alert alert-info"> <th class="text-center">Subject Code</th> <th class="text-center">Subject Title</th> <th class="text-center">Prelim</th> <th class="text-center">Midterm</th> <th class="text-center">Final</th> <th class="text-center">Final Grade</th> <th class="text-center">Equivalent</th> <!-- <th class="text-center">Units</th>--> </tr> </thead> <tbody> <?php foreach($mysubject as $row): ?> <tr> <td class="text-center"><?php echo $row['subject']; ?></td> <?php $title = $grade->getsubjectitle($conn,$row['subject']);?> <td class="text-center"><?php echo $title[0]['title']; ?></td> <?php $mygrade = $grade->getgrade($conn,$row['id']); ?> <td class="text-center"><?php echo $mygrade['prelim']; ?></td> <td class="text-center"><?php echo $mygrade['midterm']; ?></td> <td class="text-center"><?php echo $mygrade['final']; ?></td> <td class="text-center"><?php echo $mygrade['total']; ?></td> <td class="text-center"><?php echo $mygrade['eqtotal']; ?></td> <!-- <td class="text-center"><?php echo $title[0]['unit']; ?></td>--> </tr> <?php endforeach; ?> </tbody> </table> <h4 class="text-center text-danger">*** NOTHING FOLLOWS ***</h4> </div> </div> </div> <!-- <div class="row"> <?php foreach($mysubject as $row): ?> <div class="col-lg-4 gradeform"> <div class="form_hover " style="background-color: #428BCA;"> <p style="text-align: center; margin-top: 20px;"> <i class="fa fa-bar-chart-o" style="font-size: 147px;color:#fff;"></i> </p> <div class="header"> <div class="blur"></div> <div class="header-text"> <div class="panel panel-success" style="height: 247px;"> <div class="panel-heading"> <h3 style="color: #428BCA;">Subject: <?php echo $row['subject'];?></h3> </div> <div class="panel-body"> <table class="table table-bordered"> <tr class="alert alert-danger"> <th>Prelim</th> <th>Midterm</th> <th>Final</th> <th>FINAL GRADE</th> </tr> <?php $mygrade = $grade->getgrade($conn,$row['id']); ?> <tr> <td><?php echo $mygrade['prelim']; ?></td> <td><?php echo $mygrade['midterm']; ?></td> <td><?php echo $mygrade['final']; ?></td> <td><?php echo $mygrade['total']; ?></td> </tr> </table> <div class="form-group"> <?php $teacher = $grade->getteacher($conn,$row['teacher']); ?> <label>Teacher: <?php echo $teacher;?></label><br /> <label>Semester: <?php echo $row['sem']?> Sem</label><br /> </div> </div> </div> </div> </div> </div> </div> <?php endforeach; ?> </div> --> <!-- add modal for subject --> <div class="modal fade" id="changepass" tabindex="-1" role="dialog" aria-labelledby="mySmallModalLabel" aria-hidden="true"> <div class="modal-dialog modal-sm"> <div class="modal-content"> <div class="modal-header"> <h3>Change Password</h3> </div> <div class="modal-body"> <form action="password.php?q=changepassword&username=<?php echo $_SESSION['id'];?>" method="post"> <div class="form-group"> <input type="password" class="form-control" name="current" placeholder="Current Password" /> </div> <div class="form-group"> <input type="password" class="form-control" name="new" placeholder="New Password" /> </div> <div class="form-group"> <input type="password" class="form-control" name="confirm" placeholder="Confirm Password" /> </div> </div> <div class="modal-footer"> <button type="button" class="btn btn-default" data-dismiss="modal">Close</button> <button type="submit" class="btn btn-primary"><i class="fa fa-plus"></i> Change</button> </form> </div> </div> </div> </div> <hr> <footer> <p>© Company 2014</p> </footer> </div> <!-- /container --> <!-- Bootstrap core JavaScript ================================================== --> <!-- Placed at the end of the document so the pages load faster --> <script src="../js/jquery.js"></script> <script src="../js/bootstrap.min.js"></script> </body> </html>
24. marts 2020 - 11:29
#3
>Når jeg forsøger at trække data fra tabellen subjekt, kommer der ingen data frem. hvor er det du tager data ud af subjekt tabellen i den viste code ?? jeg kan ikke se nogle steder hvor der står noget ala "select * fra subjekt where xxx=yyy"
24. marts 2020 - 13:22
#4
#3: Det ligger i grade.php som han inkluderer. Koden fra den er vist højere oppe.
24. marts 2020 - 14:00
#5
#4 nej den tabel ligger der ikke, der ligger udtræk fra disse tabeller: student, studentsubject, class og der spørges efter "tabellen subjekt", jeg gætter på det ligger i methoden getsubjectitle. (ej vist) <?php $title = $grade->getsubjectitle($conn,$row['subject']);?> <?php $mygrade = $grade->getgrade($conn,$row['id']); ?>
24. marts 2020 - 16:39
#6
Jer er lige stået lidt af, I får lige hele den kodedel der hedder grade.php Kode: <?php $grade = new Datagrade(); function __construct(){ if(!isset($_SESSION['id'])){ header('location:../../'); } } class Datagrade { function __construct(){ if(!isset($_SESSION['id'])){ header('location:../../'); } } function getid($conn){ $studid = $_SESSION['id']; $r = mysqli_query($conn,"select * from `student` where studid='$studid'"); $row = mysqli_fetch_array($r, MYSQLI_BOTH); $id = $row['id']; return $id; } function getsubject($conn){ $id = $this->getid($conn); $q = "select * from `studentsubject` where studid='$id'"; $r = mysqli_query($conn,$q); $data = array(); while($row = mysqli_fetch_array($r, MYSQLI_BOTH)){ $classid = $row['classid']; $q2 = "select * from `class` where id='$classid'"; $r2 = mysqli_query($conn,$q2); $data[] = mysqli_fetch_array($r2, MYSQLI_BOTH); } return $data; } function getsubjectitle($conn,$code){ $q = "select * from `subject` where code='$code'"; $r = mysqli_query($conn,$q); $data = array(); $data[] = mysqli_fetch_array($r, MYSQLI_ASSOC); return $data; } function getgrade($conn,$classid){ $studid = $this->getid($conn); $q = "select * from `studentsubject` where studid='$studid' and classid='$classid'"; $r = mysqli_query($conn,$q); if($row = mysql_fetch_array($r, MYSQLI_ASSOC)){ $att1 = ($row['att1']) * .10; $att2 = ($row['att2']) * .10; $att3 = ($row['att3']) * .10; $exam1 = ($row['exam1']) * .50; $exam2 = ($row['exam2']) * .50; $exam3 = ($row['exam3']) * .50; $quiz1 = ($row['quiz1']) * .20; $quiz2 = ($row['quiz2']) * .20; $quiz3 = ($row['quiz3']) * .20; $project1 = ($row['project1']) * .20; $project2 = ($row['project2']) * .20; $project3 = ($row['project3']) * .20; $prelim = $att1 + $exam1 + $quiz1 + $project1; $midterm = $att2 + $exam2 + $quiz2 + $project2; $final = $att3 + $exam3 + $quiz3 + $project3; $total = ($prelim * .30) + ($midterm * .30) + ($final * .40); $data = array( 'eqprelim' => $this->gradeconversion($conn,$prelim), 'eqmidterm' => $this->gradeconversion($conn,$midterm), 'eqfinal' => $this->gradeconversion($conn,$final), 'eqtotal' => $this->gradeconversion($conn,$total), 'prelim' => round($prelim), 'midterm' => round($midterm), 'final' => round($final), 'total' => round($total), 'att1' => $row['att1'], 'att2' => $row['att2'], 'att3' => $row['att3'], 'exam1' => $row['exam1'], 'exam2' => $row['exam2'], 'exam3' => $row['exam3'], 'quiz1' => $row['quiz1'], 'quiz2' => $row['quiz2'], 'quiz3' => $row['quiz3'], 'project1' => $row['project1'], 'project2' => $row['project2'], 'project3' => $row['project3'] ); } return $data; } function gradeconversion($conn,$grade){ $grade = round($grade); if($grade==0){ $data = 0; }else{ switch ($grade) { case $grade > 94: $data = 1.0; break; case 94: $data = 1.1; break; case 93: $data = 1.2; break; case 92: $data = 1.3; break; case 91: $data = 1.4; break; case 90: $data = 1.5; break; case 89: $data = 1.6; break; case 88: $data = 1.7; break; case 87: $data = 1.8; break; case 86: $data = 1.9; break; case 85: $data = 2.0; break; case 84: $data = 2.1; break; case 83: $data = 2.2; break; case 82: $data = 2.3; break; case 81: $data = 2.4; break; case 80: $data = 2.5; break; case 79: $data = 2.6; break; case 78: $data = 2.7; break; case 77: $data = 2.8; break; case 76: $data = 2.9; break; case 75: $data = 3.0; break; default: $data = 5.0; } } return $data; } function getteacher($conn,$teachid){ $r = mysql_query("select * from `teacher` where id='$teachid'"); $result = mysql_fetch_array($r); $data = $result['fname'].' '.$result['lname']; return $data; } } ?>
24. marts 2020 - 18:50
#7
function __construct(){ uden for din class Datagrade kan du godt slette den giver ikke mening. hvordan ser din tabel student ud, og hvad indeholder den ?? >$studid = $_SESSION['id']; hvad indeholder $studid ?? hvad retunerer getid($conn) function getgrade($conn,$classid){ $studid = $this->getid($conn); $q = "select * from `studentsubject` where studid='$studid' and classid='$classid'"; $r = mysqli_query($conn,$q); // her er smuttet et i // if($row = mysql_fetch_array($r, MYSQLI_ASSOC)){ if($row = mysqli _fetch_array($r, MYSQLI_ASSOC)){
24. marts 2020 - 18:54
#8
// billige i'er til salg function getteacher($conn,$teachid){ // $r = mysql_query("select * from `teacher` where id='$teachid'"); $r = mysqli_query($conn, "select * from `teacher` where id='$teachid'"); // $result = mysql_fetch_array($r); $result = mysqil_fetch_array($r, MYSQLI_ASSOC); $data = $result['fname'].' '.$result['lname']; return $data; }
24. marts 2020 - 20:03
#9
student id - studid - fname - lname
24. marts 2020 - 20:23
#10
hvordan ser din tabel student ud, og hvad indeholder den ?? Se ovenover >$studid = $_SESSION['id']; hvad indeholder $studid ?? Skal jeg gøre noget for at teste ?? hvad retunerer getid($conn) Skal jeg gøre noget for at teste ??
24. marts 2020 - 20:53
#11
#10 prøv echo det er simple værdier de indeholder, og logge ind som en studerende, så $_SESSION['id'] bliver sat rerunerer coden det du forvendter med det indput ??, hvis ikke må du sætte nogle print_r / var_dump / echo'er ind, til du finder et sted hvor data er som det skal være
Vi tilbyder markedets bedste kurser inden for webudvikling