Roopavathy Posted August 17, 2013 Share Posted August 17, 2013 (edited) Hello, I am very new to php programming.Please help me to display the students results from the database.I want to display all the papertitle,marks etc of a particular student.Here is my code <?php include("CommentBox/includes/Connection.php"); $exno=$_GET['examno']; $query=mysql_query("Select * from results where Examno='$exno'",$con); if (!$query) { die ("Problem in query".mysql_error()); } while($row=mysql_fetch_array($query)) { if($row['Examno']==$exno) { $Examno=$row['Examno']; $studname=$row['Name']; $studrno=$row['Rno']; $studsem=$row['Sem']; $papercode=$row['Subcode']; $papertitle=$row['Title']; $studcia=$row['CIA']; $studese=$row['ESE']; $studcredits=$row['Credits']; $studgrade=$row['Grade']; $studgradept=$row['Gradept']; echo "<table> <tr> <td>Name:</td> <td>".$studname."</td> </tr> <tr> <td>Exam no:</td> <td>".$Examno."</td> </tr> <tr> <td>Roll No:</td> <td>".$studrno."</td> </tr> <tr> <td>Semester:</td> <td>".$studsem."</td> </tr></table>"; echo "<table> <tr> <td>Paper Code</td><td>Title</td><td>CIA</td> <td>ESE</td><td>Credits</td><td>Grade</td> <td>Grade Pt</td></tr>"; while($_GET['Examno']==$exno) { echo "<tr> <td>".$papercode."</td><td>".$papertitle."</td><td>".$studcia."</td><td>".$studese."</td><td>".$studcredits."</td><td>".$studgrade."</td><td>".$studgradept."</td></tr>"; } } else { echo "Invalid Number!"; } } ?> Edited August 19, 2013 by Zane Quote Link to comment Share on other sites More sharing options...
hakimserwa Posted August 17, 2013 Share Posted August 17, 2013 try this $tableOne = "<table> <tr> <td>Name:</td> <td>Exam no:</td> <td>Roll No:</td> <td>Semester:</td> </tr>"; if (!empty($row)) { foreach ($row as $data) { $tableOne .= "<tr> <td>{$data['Name']}</td> <td>{$data['Examno']}</td> <td>{$data['Rno']}</td> <td>{$data['Sem']}</td> </tr>"; } } $tableOne .= "</table>"; $tableTwo = "<table> <tr> <td>Paper Code</td> <td>Title</td> <td>CIA</td> <td>ESE</td> <td>Credits</td> <td>Grade</td> <td>Grade Pt</td> </tr>"; if (!empty($row)) { foreach ($row as $data) { $tableTwo .= "<tr> <td>{$data['Subcode']}</td> <td>{$data['Title']}</td> <td>{$data['CIA']}</td> <td>{$data['ESE']}</td> <td>{$data['Credits']}</td> <td>{$data['Grade']}</td> <td>{$data['Gradept']}</td> </tr>"; } } $tableTwo .= "</table>"; echo $tableOne; echo "<br />"; echo $tableTwo; Quote Link to comment Share on other sites More sharing options...
Roopavathy Posted August 17, 2013 Author Share Posted August 17, 2013 I have inserted the code inside my while loop but it displays like this Warning: Illegal string offset 'Name' in C:\xampp\htdocs\COMMERCE\Resultsprocess.php on line 301 and it goes on like this. Here is my code: <?phpinclude("CommentBox/includes/Connection.php");$exno=$_GET['examno'];$query=mysql_query("Select * from results where Examno='$exno'",$con);if (!$query){die ("Problem in query".mysql_error());}while($row=mysql_fetch_array($query)){$tableOne = "<table><tr><td>Name:</td><td>Exam no:</td><td>Roll No:</td><td>Semester:</td></tr>";if (!empty($row)) {foreach ($row as $data) {$tableOne .= "<tr><td>{$data['Name']}</td><td>{$data['Examno']}</td><td>{$data['Rno']}</td><td>{$data['Sem']}</td></tr>";}}$tableOne .= "</table>";$tableTwo = "<table><tr><td>Paper Code</td><td>Title</td><td>CIA</td><td>ESE</td><td>Credits</td><td>Grade</td><td>Grade Pt</td></tr>";if (!empty($row)) {foreach ($row as $data) {$tableTwo .= "<tr><td>{$data['Subcode']}</td><td>{$data['Title']}</td><td>{$data['CIA']}</td><td>{$data['ESE']}</td><td>{$data['Credits']}</td><td>{$data['Grade']}</td><td>{$data['Gradept']}</td></tr>";}}$tableTwo .= "</table>";echo $tableOne;echo "<br />";echo $tableTwo;}?> Quote Link to comment Share on other sites More sharing options...
jazzman1 Posted August 17, 2013 Share Posted August 17, 2013 What happens when you ran the script of your first post? Did you get some errors or just a blank page? Quote Link to comment Share on other sites More sharing options...
mac_gyver Posted August 17, 2013 Share Posted August 17, 2013 @Roopavathy, your code is not logical and some of it is not doing anything (that needs to be in there.) line 13 (in your post) if($row['Examno']==$exno) is testing if the row matches $exno. you already know that will be true because that's the condition you put in your query. line 50 (in your post) while($_GET['Examno']==$exno) is looping while the get variable matches $exno. again you already know that will be true because on line 3 in your posted code you have set $exno=$_GET['examno']; also, this while(){} loop will loop forever (or until php times out) because the condition being tested never changes. next, you have 12 column values you are using inside of your loop. you don't need to create separate variables from each value (saving 12 lines of code). you can just use the $row['Examno']... variables directly in your code, especially since you are using each one only one time. you can also put php variables inside of double-quoted strings " ... " without using concatenation. an array variable like $row['Name'] does need {} around it when put into a string. what your posted code would look like without the unnecessary bits - include("CommentBox/includes/Connection.php"); $exno=$_GET['examno']; $query=mysql_query("Select * from results where Examno='$exno'",$con); if (!$query){ die ("Problem in query".mysql_error($con)); } while($row=mysql_fetch_assoc($query)) { echo "<table> <tr><td>Name:</td><td>{$row['Name']}</td></tr> <tr><td>Exam no:</td><td>{$row['Examno']}</td></tr> <tr><td>Roll No:</td><td>{$row['Rno']}</td></tr> <tr><td>Semester:</td><td>{$row['Sem']}</td></tr> </table>"; echo "<table> <tr><td>Paper Code</td><td>Title</td><td>CIA</td><td>ESE</td><td>Credits</td><td>Grade</td><td>Grade Pt</td></tr> <tr><td>{$row['Subcode']}</td><td>{$row['Title']}</td><td>{$row['CIA']}</td><td>{$row['ESE']}</td> <td>{$row['Credits']}</td><td>{$row['Grade']}</td><td>$row['Gradept']</td></tr> </table>"; } finally, is that your intended output? one table with the student information, followed by a second table with the exam information for that student, repeat both tables for each student? Quote Link to comment Share on other sites More sharing options...
Roopavathy Posted August 19, 2013 Author Share Posted August 19, 2013 I want to show a screen shot about my results page.But don't know how to insert.Please help. Quote Link to comment Share on other sites More sharing options...
Roopavathy Posted August 19, 2013 Author Share Posted August 19, 2013 Are there anyone to help me.I want to show you an image.Pls help me..................... Quote Link to comment 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.