Jump to content

All Activity

This stream auto-updates

  1. Past hour
  2. Today
  3. Yesterday
  4. 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.
  5. 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.
  6. Last week
  7. 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.
  8. Thanks for the reply, That makes a lot of sense.
  9. When you connect to postgresql you specify a database. If you are connecting to the database you are trying to drop, you will be blocking your ability to drop it. Make sure you connect to the postgres database. If that is not the issue, and you are not connecting to mydb, you should be able to drop the database regardless of any other existing connections to it, using: drop database mydb with (force)
  10. The two ways are significantly different. The first way is the way you should do this. It uses the curl extension that is built into PHP. The 2nd way is creating a system shell and then executing a shell command that in your case happens to be the curl command. Many things could go wrong, and you will not have visibility into those issues. It is a less direct method, and doesn't have the same level of access to curl options and results.
  11. 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>
  12. In trying to get the text off a particular website, I've used two different ways, both of which seem to work fine & give the exact same results.. I was wondering if anyone could give me any insight or recommendations why one way might be any better or worse than the other . I've used these two ways: $ch1=curl_init(); curl_setopt($ch1,CURLOPT_URL,$link1); curl_setopt($ch1,CURLOPT_RETURNTRANSFER, true); $text1=curl_exec($ch1); // or $text1 = shell_exec('curl '.$link1 ); The second way seems easier & speedwise they both are about the same I've also tried "file_get_contents" which also gives the same results but is obviously slower.
  13. If this is for validation of emails, then a simple and effective solution would be to utilize filter_var. $email = '[email protected]'; function validEmail($email) { return filter_var($email, FILTER_VALIDATE_EMAIL); } if (!validEmail($email)) { echo "The email address provided is not valid"; }
  14. In today’s digital world, having a strong online presence is essential for the growth of any business. Whether you're a small startup or a large enterprise, standing out from the competition requires a robust strategy. As a SEO expert in Hyderabad with over 10 years of experience, I can help businesses like yours get noticed online and attract the right audience. But how do you take your business website to the next level? The solution lies in partnering with a freelance web designer in Hyderabad and a skilled SEO expert. Here’s why these professionals are crucial for your success: 1. Tailored SEO Strategy to Boost Your Visibility Search Engine Optimization (SEO) is the foundation of any successful online marketing strategy. Without the right SEO approach, your website may struggle to rank on search engines like Google. As an SEO freelancer in Hyderabad, I offer personalized strategies to ensure that your website ranks higher, bringing in organic traffic and improving your visibility. From keyword research to optimizing meta tags and ensuring proper on-page SEO, I focus on improving every aspect of your website to get noticed by search engines and attract more visitors. By hiring an SEO expert in Hyderabad, you gain the expertise needed to achieve lasting SEO success. 2. Custom Web Design That Represents Your Brand Your website is often the first interaction potential customers have with your brand, which is why it must look professional, function seamlessly, and represent your business well. As a freelance web designer in Hyderabad, I design user-friendly, responsive websites that are not only visually appealing but also optimized for performance. A great design enhances user experience, reduces bounce rates, and leads to higher conversion rates. By combining SEO and web design expertise, I ensure that your website isn’t just pretty - it also functions well and gets noticed on search engines. 3. Graphic Design That Captures Attention Graphic design plays a significant role in creating a memorable brand identity. Whether it’s your website’s visual elements, logos, or social media graphics, engaging visuals can help convey your brand message effectively. As a freelancer graphic designer in Hyderabad, I create custom graphics that resonate with your target audience and help you stand out. Great graphics can increase user engagement, create trust, and give your business a unique identity online. With my design skills, I ensure that your brand is consistent across all platforms and truly represents your business values. 4. Comprehensive Digital Marketing Approach Hiring an SEO expert in Hyderabad ensures you receive a holistic approach to digital marketing. From optimizing your website to enhancing your social media presence, I offer end-to-end services that help drive traffic and convert visitors into loyal customers. A comprehensive strategy not only involves improving SEO but also integrating elements of design and branding that boost your online reputation and make you a trusted name in your industry. Conclusion : If you're looking to take your business online to the next level, partnering with an SEO freelancer in Hyderabad, freelance web designer in Hyderabad, and a freelancer graphic designer in Hyderabad is a smart move. With over 10 years of experience in SEO, website design, and graphic design, I offer personalized services to ensure your website ranks higher, looks fantastic, and communicates your brand effectively. Don't let your business get lost in the digital noise - contact me today, and let's work together to create a powerful online presence that drives results!
  15. So, are we to guess what you have done so far? Or, will you enlighten us by providing us with what you have done so far?
  16. To remove the X-PHP headers from your email, you can use the ini_set() function to disable the addition of these headers before sending your email.
  17. 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.
  18. Please i tried to modified my table with some related tables joins so that i can have the results dynamic but the my table is not appearing again. Please i need your help. How can i contact you privately? SELECT school.school, school.logo, student.gender, student.program, student.house, student.enstatus, 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='2024/2025' AND marks.semester='1' AND marks.form='3' AND marks.class='SCI A' ORDER BY name, subject
  19. PS You aren't doing yourself any favours by insisting on mysqli. PDO is a superior library and easier to use. While you are still learning, put your effort into PDO
  20. Change $pdo = pdoConnect(); to $pdo = new mysqli(HOST, USERNAME, PASSWORD, DATABASE); Job done.
  21. Please i saw your code but i am not able to use it because you used PDO instead of MySQLI. can you code it in mysqli for me to see if i can use it. Thank you. <?php define("HOST", 'localhost'); define("USERNAME", '????'); define("PASSWORD", '????'); define("DATABASE", '????'); // default database name 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 marks.acayear , marks.semester , marks.form , marks.class , marks.studentid , marks.name , marks.subject , marks.class_score1 , marks.exam_score1 , ROUND(marks.total, 1) as total , marks.grade , marks.remarks , RANK() OVER (PARTITION BY marks.acayear, marks.semester, marks.lessonsid ORDER BY marks.total DESC) as rank FROM marks WHERE marks.acayear='2024/2025' AND marks.semester='1' AND marks.form='3' AND marks.class='SCI A' 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, 6)); $previd = $r['studentid']; } $tdata .= outputSubject(...array_slice($r, 6)); // close last report } $tdata .= "\n</table>\n</div>\n</div>\n\n"; # # FUNCTIONS # function outputReportHeading($acayear, $semester, $form, $class, $studentid, $name) { return <<<HEAD <div class='report w3-container w3-white'> <div class='report-head'> SAVELUGU SENIOR HIGH SCHOOL </div> <div class='report-head'> $acayear ACADEMIC YEAR </div> <div class='w3-row w3-margin-top'> <div class='w3-col m1 w3-center'> [SCHOOL<br>CREST] </div> <div class='w3-col m5 report-subhead'> Student ID: <span class='hval'>$studentid</span> <br> Name: <span class='hval'>$name</span> <br> Semester: <span class='hval'>$semester</span> </div> <div class='w3-col m5 report-subhead'> House: <span class='hval'></span> <br> Gender: <span class='hval'></span> <br> Class: <span class='hval'>$form $class</span> </div> <div class='w3-col m1 w3-center'> [PHOTO] </div> </div> <div class='report-head w3-margin-top'> STUDENT TERMINAL REPORT </div> <div class='w3-responsive'> <table border='1' class='scores'> <tr> <th>Subject</th> <th class='w3-hide-small'>Class Score</th> <th class='w3-hide-small'>Exam Score</th> <th>Total</th> <th>Grade</th> <th>Pos</th> <th>Remarks</th> </tr> HEAD; } function outputSubject($subject, $class_score1, $exam_score1, $total, $grade, $remarks, $rank) { return <<<SUB <tr> <td>$subject</td> <td class='w3-hide-small ca'>$class_score1</td> <td class='w3-hide-small ca'>$exam_score1</td> <td class='ca'>$total</td> <td class='ca'>$grade</td> <td class='ca'>$rank</td> <td>$remarks</td> </tr> SUB; } ?> <!DOCTYPE html> <html lang="en"> <head> <title>Example Reports 1</title> <meta charset="utf-8"> <link rel="stylesheet" href="https://www.w3schools.com/w3css/4/w3.css"> <style type='text/css'> body { background-color: #FCF8E8; } .report { margin: 16px; padding: 8px; border: 1px solid gray; } .report-head { font-size: 18pt; font-weight: 600; text-align: center; } .report-subhead { font-size: 14pt; font-weight: 300; } .hval { font-weight: 600; color: blue; } .scores { width: 100%; border-collapse: collapse; } th { padding: 8px 2px; background-color: gray; color: white; } td { padding: 8px 4px; } .ca { text-align: center; } </style> </head> <body> <?= $tdata ?> </body> </html>
  22. Earlier
  23. BTW, it seems a pity that that those students who attain a C6 grade should receive only an anagram instead of a Credit
  24. Woow!!!, the world is full of knowledgeable people. Mr. Barand, how can i learn this coding you have done? I will be grateful if you can support me as the saying goes ''It is better teaching how to fish than giving me fish". Words alone cannot express my happiness. I am so much grateful you. Than you.
  25. I'm trying to drop a PostgreSQL database using the DROP DATABASE mydb command, but I getting this error: Please help me with any guidance....
  26. @sule, Here are two version of the program A single loop tracking changes in studentid (as I suggested) Stores data in a muti-dimensional array and uses nested foreach() loops Version 1 <?php define("HOST", 'localhost'); define("USERNAME", '????'); define("PASSWORD", '????'); define("DATABASE", '????'); // default database name 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 marks.acayear , marks.semester , marks.form , marks.class , marks.studentid , marks.name , marks.subject , marks.class_score1 , marks.exam_score1 , ROUND(marks.total, 1) as total , marks.grade , marks.remarks , RANK() OVER (PARTITION BY marks.acayear, marks.semester, marks.lessonsid ORDER BY marks.total DESC) as rank FROM marks WHERE marks.acayear='2024/2025' AND marks.semester='1' AND marks.form='3' AND marks.class='SCI A' 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, 6)); $previd = $r['studentid']; } $tdata .= outputSubject(...array_slice($r, 6)); // close last report } $tdata .= "\n</table>\n</div>\n</div>\n\n"; # # FUNCTIONS # function outputReportHeading($acayear, $semester, $form, $class, $studentid, $name) { return <<<HEAD <div class='report w3-container w3-white'> <div class='report-head'> SAVELUGU SENIOR HIGH SCHOOL </div> <div class='report-head'> $acayear ACADEMIC YEAR </div> <div class='w3-row w3-margin-top'> <div class='w3-col m1 w3-center'> [SCHOOL<br>CREST] </div> <div class='w3-col m5 report-subhead'> Student ID: <span class='hval'>$studentid</span> <br> Name: <span class='hval'>$name</span> <br> Semester: <span class='hval'>$semester</span> </div> <div class='w3-col m5 report-subhead'> House: <span class='hval'></span> <br> Gender: <span class='hval'></span> <br> Class: <span class='hval'>$form $class</span> </div> <div class='w3-col m1 w3-center'> [PHOTO] </div> </div> <div class='report-head w3-margin-top'> STUDENT TERMINAL REPORT </div> <div class='w3-responsive'> <table border='1' class='scores'> <tr> <th>Subject</th> <th class='w3-hide-small'>Class Score</th> <th class='w3-hide-small'>Exam Score</th> <th>Total</th> <th>Grade</th> <th>Pos</th> <th>Remarks</th> </tr> HEAD; } function outputSubject($subject, $class_score1, $exam_score1, $total, $grade, $remarks, $rank) { return <<<SUB <tr> <td>$subject</td> <td class='w3-hide-small ca'>$class_score1</td> <td class='w3-hide-small ca'>$exam_score1</td> <td class='ca'>$total</td> <td class='ca'>$grade</td> <td class='ca'>$rank</td> <td>$remarks</td> </tr> SUB; } ?> <!DOCTYPE html> <html lang="en"> <head> <title>Example Reports 1</title> <meta charset="utf-8"> <link rel="stylesheet" href="https://www.w3schools.com/w3css/4/w3.css"> <style type='text/css'> body { background-color: #FCF8E8; } .report { margin: 16px; padding: 8px; border: 1px solid gray; } .report-head { font-size: 18pt; font-weight: 600; text-align: center; } .report-subhead { font-size: 14pt; font-weight: 300; } .hval { font-weight: 600; color: blue; } .scores { width: 100%; border-collapse: collapse; } th { padding: 8px 2px; background-color: gray; color: white; } td { padding: 8px 4px; } .ca { text-align: center; } </style> </head> <body> <?= $tdata ?> </body> </html> Version 2 <?php define("HOST", 'localhost'); define("USERNAME", '????'); define("PASSWORD", '????'); define("DATABASE", '????'); // default database name 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 marks.acayear , marks.semester , marks.form , marks.class , marks.studentid , marks.name , marks.subject , marks.class_score1 , marks.exam_score1 , ROUND(marks.total, 1) as total , marks.grade , marks.remarks , RANK() OVER (PARTITION BY marks.acayear, marks.semester, marks.lessonsid ORDER BY marks.total DESC) as rank FROM marks WHERE marks.acayear='2024/2025' AND marks.semester='1' AND marks.form='3' AND marks.class='SCI A' ORDER BY name, subject; "); $tdata = ''; # # store the data in a 3D array # $data = []; foreach ($res as $r) { if (!isset($data[$r['studentid']])) { $data[$r['studentid']] = [ 'head' => array_slice($r, 0, 6), 'scores' => [] ]; } $data[$r['studentid']]['scores'][] = array_slice($r, 6); } # echo '<pre>' . print_r($data, 1) . '</pre>'; // uncomment to view array structure # # PROCESS THE ARRAY # foreach ($data as $sdata) { $tdata .= outputReportHeading(...$sdata['head']); foreach ($sdata['scores'] as $subdata) { $tdata .= outputSubject(...$subdata); } $tdata .= "\n</table>\n</div>\n</div>\n\n"; } # # FUNCTIONS # function outputReportHeading($acayear, $semester, $form, $class, $studentid, $name) { return <<<HEAD <div class='report w3-container w3-white'> <div class='report-head'> SAVELUGU SENIOR HIGH SCHOOL </div> <div class='report-head'> $acayear ACADEMIC YEAR </div> <div class='w3-row w3-margin-top'> <div class='w3-col m1 w3-center'> [SCHOOL<br>CREST] </div> <div class='w3-col m5 report-subhead'> Student ID: <span class='hval'>$studentid</span> <br> Name: <span class='hval'>$name</span> <br> Semester: <span class='hval'>$semester</span> </div> <div class='w3-col m5 report-subhead'> House: <span class='hval'></span> <br> Gender: <span class='hval'></span> <br> Class: <span class='hval'>$form $class</span> </div> <div class='w3-col m1 w3-center'> [PHOTO] </div> </div> <div class='report-head w3-margin-top'> STUDENT TERMINAL REPORT </div> <div class='w3-responsive'> <table border='1' class='scores'> <tr> <th>Subject</th> <th class='w3-hide-small'>Class Score</th> <th class='w3-hide-small'>Exam Score</th> <th>Total</th> <th>Grade</th> <th>Pos</th> <th>Remarks</th> </tr> HEAD; } function outputSubject($subject, $class_score1, $exam_score1, $total, $grade, $remarks, $rank) { return <<<SUB <tr> <td>$subject</td> <td class='w3-hide-small ca'>$class_score1</td> <td class='w3-hide-small ca'>$exam_score1</td> <td class='ca'>$total</td> <td class='ca'>$grade</td> <td class='ca'>$rank</td> <td>$remarks</td> </tr> SUB; } ?> <!DOCTYPE html> <html lang="en"> <head> <title>Example Reports 2</title> <meta charset="utf-8"> <link rel="stylesheet" href="https://www.w3schools.com/w3css/4/w3.css"> <style type='text/css'> body { background-color: #FCF8E8; } .report { margin: 16px; padding: 16px; border: 1px solid gray; } .report-head { font-size: 18pt; font-weight: 600; text-align: center; } .report-subhead { font-size: 14pt; font-weight: 300; } .hval { font-weight: 600; color: blue; } .scores { width: 100%; border-collapse: collapse; } th { padding: 8px 2px; background-color: gray; color: white; } td { padding: 8px 4px; } .ca { text-align: center; } </style> </head> <body> <?= $tdata ?> </body> </html> Samples
  27. Thank you for assistance. I am still a newbie who is learning php mysql myself without any mentor. It is my passion of using the web to solve problems at my work place. After my first degree in information technology i wanted to help my people use the web at local level to solve their problems. I am grateful for your response and advice given me. By the way I am from Ghana
  28. this is the thead section - <thead> <tr class="text-center"> <th class="th-sm text-center">Subject </th> <th class="th-sm text-center">Class Score <br>(30%) </th> <th class="th-sm text-center">Exam Score <br>(70%) </th> <th class="th-sm text-center">Total <br>(100%) </th> <th class="th-sm text-center">Grade </th> <th class="th-sm text-center">Position </th> <th class="th-sm text-center">Remarks </th> </tr> </thead> it is the same for every student. your output is incorrect because the markup you are producing is broken. the code inside the loop is incorrect. the reason I posted an outline of what the code should do is to help you to be able to produce the correct output that will work. i recommend that you validate the resulting web page at validator.w3.org
  29. The table head is not one because each student have a table which need to be looped. I can't just figure out why the first row data appears ones without its tables
  1. Load more activity
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.