MjM8082 Posted September 18, 2011 Share Posted September 18, 2011 Okay so I have a table that displays grades. If the stupid has 100 for the grade points then I want a A to be displayed under the table... I think it does something like this... if grade_type >=100 $final_grade = A Idk, im new to php and need help doing this... here is my code... <?php ini_set ("display_errors", "1"); error_reporting(E_ALL); require_once('database.php'); session_start(); if (isset($_POST['add_grade'])) { $query = "INSERT INTO grades (grade_id, student_id, grade_type, grade_name, grade_points) "; $query .= "VALUES (:grade_id, :student_id, :grade_type, :grade_name, :grade_points) "; $statement = $db->prepare($query); $statement->bindValue (':student_id', $_SESSION['student_id']); $statement->bindValue (':grade_id', $_SESSION['grade_id']); $statement->bindValue (':grade_type', $_POST['grade_type']); $statement->bindValue (':grade_name', $_POST['grade_name']); $statement->bindValue (':grade_points', $_POST['grade_points']); $statement->execute(); $statement->closeCursor(); } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>View Course Grades</title> <link rel="stylesheet" type="text/css" href="main.css" /> </head> <body> <?php $student_name = $_SESSION['student_name']; $student_id = $_SESSION['student_id']; $query = "SELECT * FROM grades WHERE student_id = :student_id "; $statement = $db->prepare($query); $statement->bindValue (':student_id', $student_id); $statement->execute(); $grades = $statement->fetchAll(); $statement->closeCursor(); echo "<h1>Show Grades for $student_name </h1>"; foreach ($grades as $grade) { echo $grade['grade_type'] . " " . $grade['grade_name']. " " . $grade['grade_points'] . "<br />"; } ?> <div id="content"> <!-- display a table of products --> <table> <tr> <th>Grade Type</th> <th>Grade Name</th> <th>Grade Points</th> <th>Remove</th> </tr> <?php foreach ($grades as $grade) : ?> <tr> <td><?php echo $grade['grade_type']; ?></td> <td><?php echo $grade['grade_name']; ?></td> <td><?php echo $grade['grade_points']; ?></td> <td><form action="delete_grade.php" method="post"> <input type="submit" name="remove" value="Delete" /> <input type="submit" name="update" value="Update" /> </form></td> </tr> <?php endforeach; ?> </table> </div> </div> <div id="footer"> </div> <form name="grades" method="post" action="grades.php"> <p>Grade Type<SELECT NAME="grade_type"> <OPTION VALUE="Mid-Term">Mid-Term <OPTION VALUE="Final">Final <OPTION VALUE="Lab">Lab </SELECT> <br> Grade Name:<input type="text" name="grade_name" value=""><br /> Grade Points:<input type="text" name="grade_point" value=""> <input type="submit" name="add_grade" value="Add Grade"> </form> </table> </body> </html> <html> <head> <title>Delete Grade</title> </head> <body> <form method="post" action="delete_grade.php"> <?php ini_set ("display_errors", "1"); error_reporting(E_ALL); $dbc = mysqli_connect('localhost', 'se266_user', 'pwd', 'se266') or die(mysql_error()); //delete grades if (isset($_POST['remove'])) { foreach($_POST['delete'] as $delete_id) { $query = "DELETE FROM grades WHERE grade_id = $delete_id"; mysqli_query($dbc, $query) or die ('can\'t delete user'); } echo 'grade has been deleted.<br />'; } if (isset($_POST['update'])) { foreach($_POST['update'] as $update_id) { $query = "UPDATE grades SET grade_id = $update_id"; mysqli_query($dbc, $query) or die ('can\'t update user'); } } //Display grade info with checkbox to delete $query = "SELECT * FROM grades"; $result = mysqli_query($dbc, $query); while($row = mysqli_fetch_array($result)) { echo '<input type="checkbox" value="' .$row['grade_id'] . '" name="delete[]" />'; echo ' ' .$row['grade_type'] .' '. $row['grade_name']; echo '<br />'; } mysqli_close($dbc); ?> <p>Grade Type<SELECT NAME="grade_type"> <OPTION VALUE="Mid-Term">Mid-Term <OPTION VALUE="Final">Final <OPTION VALUE="Lab">Lab </SELECT> <br> Grade Name:<input type="text" name="grade_name" value=""><br /> Grade Points:<input type="text" name="grade_point" value=""> <input type="submit" name="remove" value="Remove" /> <input type="submit" name="update" value="Update" /> </form> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/247360-need-help-with-simple-code/ Share on other sites More sharing options...
Pandemikk Posted September 18, 2011 Share Posted September 18, 2011 ? if ($students_grade >= 100) { $final_grade = 'A'; } Quote Link to comment https://forums.phpfreaks.com/topic/247360-need-help-with-simple-code/#findComment-1270336 Share on other sites More sharing options...
MjM8082 Posted September 18, 2011 Author Share Posted September 18, 2011 where exactly would I put that in my code? so that it will work properly Quote Link to comment https://forums.phpfreaks.com/topic/247360-need-help-with-simple-code/#findComment-1270337 Share on other sites More sharing options...
Pandemikk Posted September 18, 2011 Share Posted September 18, 2011 That's up to you! Do you want it to be added into the database? Then put it before the query. And just to let you know: "$students_grade" is just a made up variable. I don't know where the actual student's grade is stored in in your code. Quote Link to comment https://forums.phpfreaks.com/topic/247360-need-help-with-simple-code/#findComment-1270339 Share on other sites More sharing options...
voip03 Posted September 18, 2011 Share Posted September 18, 2011 Where would you like to display the final grade? Quote Link to comment https://forums.phpfreaks.com/topic/247360-need-help-with-simple-code/#findComment-1270340 Share on other sites More sharing options...
creata.physics Posted September 18, 2011 Share Posted September 18, 2011 Okay so I have a table that displays grades. If the stupid has 100 for the grade points then I want a A to be displayed under the table... I think it does something like this... If the stupid...instead of student. that's pretty damn funny. You can add $final_grade inside another column and row in the table in the first file you showed us. Quote Link to comment https://forums.phpfreaks.com/topic/247360-need-help-with-simple-code/#findComment-1270341 Share on other sites More sharing options...
MjM8082 Posted September 18, 2011 Author Share Posted September 18, 2011 I want to display it underneath the table. I want it to say "Your Final Grade Is... " I'm not sure where to put the code, but I tried to put it into my code as this... if ($grade_points >= 100) { $final_grade = 'A'; } But it keeps saying grade_points is undefined Quote Link to comment https://forums.phpfreaks.com/topic/247360-need-help-with-simple-code/#findComment-1270343 Share on other sites More sharing options...
voip03 Posted September 18, 2011 Share Posted September 18, 2011 if ($grade_points >= 100) { $final_grade = 'A'; echo $final_grade; } elseif( ($grade_points >= 80) && ($grade_points <=100)) { $final_grade = 'B'; echo $final_grade; } Quote Link to comment https://forums.phpfreaks.com/topic/247360-need-help-with-simple-code/#findComment-1270350 Share on other sites More sharing options...
Pandemikk Posted September 18, 2011 Share Posted September 18, 2011 Voip, stop replying to threads without reading them first. Your post has nothing to do with what OP is asking for! MjM, if $grade_points is undefined you'll need to use the actual variable that contains the grade's of your student. Quote Link to comment https://forums.phpfreaks.com/topic/247360-need-help-with-simple-code/#findComment-1270457 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.