Barand Posted March 19 Share Posted March 19 Put this line just before the mysqli connection code... mysqli_report(MYSQLI_REPORT_ERROR|MYSQLI_REPORT_STRICT); Ensure error_reporting is ON. You should now get error messages if there are problems with a query. Quote Link to comment https://forums.phpfreaks.com/topic/327024-generate-students-postions-based-on-marks-scored-in-an-exam/page/2/#findComment-1651723 Share on other sites More sharing options...
sule Posted Friday at 10:38 PM Author Share Posted Friday at 10:38 PM database.txt Quote Link to comment https://forums.phpfreaks.com/topic/327024-generate-students-postions-based-on-marks-scored-in-an-exam/page/2/#findComment-1651899 Share on other sites More sharing options...
sule Posted Sunday at 03:47 PM Author Share Posted Sunday at 03:47 PM Thank you Mr. Barand my code is now working but want to add comments to every student so that the form master can comment about student's conduct attitude and interest fot parent to monitor students progress. The print out should also be one student per page <?php include 'session.php'; ?> <?php include '../db/dbconnect.php'; define("HOST", 'localhost'); define("USERNAME", 'root'); define("PASSWORD", ''); define("DATABASE", 'sms'); ?> <!doctype html> <html lang="en"> <head> <!-- Required meta tags --> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta http-equiv="X-UA-Compatible" content="ie=edge"> <link rel="stylesheet" href="../css/bootstrap.min.css" /> <link rel="stylesheet" href="../bootstrap-icons/font/bootstrap-icons.min.css"> <link rel="stylesheet" href="../bootstrap-icons/font/bootstrap-icons.min.css"> <link rel="stylesheet" type="text/css" href="../css/viewpasscodeadmin.css" /> <link rel="stylesheet" href="../css/report1.css"> <link rel="stylesheet" href="../font/stylesheet.css"> <link rel="stylesheet" href="../css/dataTables.bootstrap5.css" /> <link rel="stylesheet" href="../css/buttons.bootstrap5.css" /> <link rel="stylesheet" href="../css/responsive.bootstrap5.css" /> <link rel="stylesheet" href="../font/stylesheet.css"> <title>report</title> </head> <body> <div class="container"> <?php //error_reporting(0); ?> <?php if (isset($_POST['submit'])) { $acayear = mysqli_real_escape_string($con, $_POST['acayear']); $semester = mysqli_real_escape_string($con, $_POST['semester']); $form = mysqli_real_escape_string($con, $_POST['form']); $class = mysqli_real_escape_string($con, $_POST['class']); } function pdoConnect($dbname = DATABASE) { $db = new PDO("mysql:host=" . HOST . ";dbname=$dbname;charset=utf8", USERNAME, PASSWORD); $db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); $db->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_ASSOC); $db->setAttribute(PDO::ATTR_EMULATE_PREPARES, false); $db->setAttribute(PDO::MYSQL_ATTR_LOCAL_INFILE, true); return $db; } $pdo = pdoConnect(); $res = $pdo->query("SELECT school.school, school.logo, student.gender, student.program, student.house, student.image, marks.acayear, marks.semester, marks.form ,marks.class, marks.studentid, marks.name, marks.subject, marks.class_score1, marks.exam_score1,marks.total, marks.grade, marks.remarks, RANK() OVER (PARTITION BY marks.acayear, marks.semester, marks.lessonsid ORDER BY marks.total DESC) as rank FROM marks LEFT JOIN student ON marks.studentid=student.studentid LEFT JOIN school ON student.schoolid=school.schoolid WHERE marks.acayear='{$acayear}' AND marks.semester='{$semester}' AND marks.form='{$form}' AND marks.class='{$class}' ORDER BY name, subject"); $previd = 0; $tdata = ''; foreach ($res as $r) { if ($r['studentid'] != $previd) { if ($previd != 0) { // if not the first $tdata .= "\n</table>\n</div>\n</div>\n\n"; // close preceding report } $tdata .= outputReportHeading(...array_slice($r, 0, 12)); $previd = $r['studentid']; } $tdata .= outputSubject(...array_slice($r, 7)); // close last report } $tdata .= "\n</table>\n</div>\n</div>\n\n"; # # FUNCTIONS # function outputReportHeading($school, $logo, $gender, $program, $house, $image, $acayear, $semester, $form, $class, $studentid, $name) { return <<<HEAD <div class="logo1"> <img src="../uploads/student/$image" width="100px" class="rounded float-end mt-3"> </div> <div class="logo"> <img src="../uploads/logo/$logo" width="100px" class="rounded float-start mt-3"> </div> <div class="heading mt-2"> $school </div> <div class="heading2"><b> $acayear ACADEMIC YEAR</b> </div> <div class='heading2'> <b>Student ID:</b> <span class=''>$studentid</span> <b>Name of Student:</b> <span class=''>$name</span> <br> <b>Semester:</b> <span'>$semester</span> <b>House:</b> <span>$house</span> <b>Gender:</b> <span>$gender</span> <b>Program:</b> <span>$program</span> <b>Class:</b> <span>$form $class</span> </div> <div class="heading"> STUDENT TERMINAL REPORT </div> <div class="tablewrap mt-2"> <table class="table table-bordered table-sm" cellspacing="0" width="100%"> <thead> <tr class="text-center"> <th class="th-sm text-left">Subject</th> <th class="th-sm text-center">Class Score</th> <th class="th-sm text-center">Exam Score</th> <th class="th-sm text-center" >Total</th> <th class="th-sm text-center">Grade</th> <th class="th-sm text-center" >Pos</th> <th class="th-sm text-center" >Remarks</th> </tr> <thead> HEAD; } function outputSubject($semester, $form, $class, $studentid, $name, $subject, $class_score1, $exam_score1, $total, $grade, $remarks, $rank) { return <<<SUB <tbody> <tr> <td class="text-left" >$subject</td> <td class="text-center">$class_score1</td> <td class="text-center">$exam_score1</td> <td class="text-center">$total</td> <td class="text-center">$grade</td> <td class="text-center">$rank</td> <td class="text-left">$remarks</td> </tr> </div> </tbody> SUB; } ?> <?= $tdata; ?> </div>. </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/327024-generate-students-postions-based-on-marks-scored-in-an-exam/page/2/#findComment-1652018 Share on other sites More sharing options...
mac_gyver Posted Sunday at 11:44 PM Share Posted Sunday at 11:44 PM and what exactly is the problem with the last posted code? here are some points for the current code - you should use a single database extension. now that you have used the much simpler and better designed PDO extension, all your code should be updated to use the extension. you should NOT use the mysqli_real_escape_string() function, which probably doesn't have the character-set set, to match your database tables, when the connection was made, then put these pieces of data directly into the sql query statement, as this can allow sql special charters in a value to break the sql query syntax. you should use a prepared query. converting a query that has php variables being put into it into a prepared query is straight forward. if you need, someone can post a list of instructions how to do this. you should use a get method form when determining what will be displayed on a page. this is so that if someone finds a result they want to return to or share with someone, they can bookmark the URL or share the URL and be able to return to the same result. the search form should be on the same page as the result and the form should be 'sticky' and repopulate the fields, selected options, checkboxes, and radiobuttons with any existing values so that if the search doesn't find what the user expects, they can simply make changes to the search values and try again. all the search form processing code should be inside the conditional statement testing if the form has been submitted. the current code will produce a bunch of php errors and likely produce no search result and output if the page is requested without any form data. you need to trim, mainly so that you can detect if all white-space characters were entered, then validate all input data before using it. the search inputs you have shown are all 'required'. if they are not all valid, you should output error messages stating what is wrong with them and NOT run any of the query/output code. if you want to make any of these search inputs 'optional' you will need to dynamically build the WHERE part of the query and only include the terms that have search values. the use of LEFT JOIN doesn't make sense (to me). it indicates that you want to get marks data that may not have any student or school associated with it. you should just use a JOIN if you only want marks data that has school/student data. if a query doesn't match any data, you should output a message stating so, rather than outputting nothing. you need to apply htmlentities() to dynamic values being output in a html context, right before/as they are being output in order to prevent any html entities in a value from being able to break the html syntax. Quote Link to comment https://forums.phpfreaks.com/topic/327024-generate-students-postions-based-on-marks-scored-in-an-exam/page/2/#findComment-1652028 Share on other sites More sharing options...
sule Posted Monday at 04:47 PM Author Share Posted Monday at 04:47 PM You don't understand the structure of my code that is why. But i take all your submissions and Thanks The submit is a request coming from a form in another page. Quote Link to comment https://forums.phpfreaks.com/topic/327024-generate-students-postions-based-on-marks-scored-in-an-exam/page/2/#findComment-1652067 Share on other sites More sharing options...
mac_gyver Posted Monday at 05:24 PM Share Posted Monday at 05:24 PM you didn't answer what is wrong with the last posted code/output? i understand your code perfectly. the list of programming practices will help to - secure your web site, provide a good User eXperience (UX), simplifies the code, and corrects some mistakes. i looked back at the search form, here's a similar list for it (repeats some things already posted) - to get a form to submit to the same page it is on, simply leave out the entire action attribute. as already written, this should be get method form and it should be 'sticky' and reselect any existing option choices. you need to validate the resulting web pages at validator.w3.org you should list out the columns you are SELECTing and only list the ones you are using in the code. you should (almost) always fetch data using an associate index name so that if your database table gets rearranged the code will still work and your code will be self-documenting (anyone reading it can tell what it is doing without needing to know what your table definitions are). any query that can match more than one row of data needs an ORDER BY ... term so that the data is in an expected order. some of your queries have an ORDER BY, some don't. using a character data type for numerical data won't sort correctly once you have values with more than a single character length. you should use a numerical data type for numerical data. the default ORDER BY ... direction is ASC. you don't need to specify it in a query. if a query doesn't match any data, you should output a message stating so, instead of outputting nothing. you need to apply htmlentities() to dynamic values being output in a html context, right before/as they are being output in order to prevent any html entities in a value from being able to break the html syntax. if you use php's short-open-print-tag <?= it will save typing. also, you can leave out the closing ; right before a closing tag ?> saving typing. there's a ; on the end of all the while ():; statements. this should either be a syntax error or is short-circuiting the loop and should be removed. for the 'required' attribute to work for a select/option menu, the first option choice must have an empty value and serve as a prompt to make a choice. you only need to use the 'required' attribute, you don't need the ="required" value. for a <label> to work, you must either have a for='...' attribute and a corresponding id='...' attribute in the field or more simply just put the closing </label> tag after the form field it corresponds to. if you have a <label>, you cannot have an empty display item for the first <option></option> choice. don't use a series of name-numbered variables. you are/should be completely dealing with the result of one query before going on to the next. just reuse simple variable names. Quote Link to comment https://forums.phpfreaks.com/topic/327024-generate-students-postions-based-on-marks-scored-in-an-exam/page/2/#findComment-1652071 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.