Php-MySQL- -> Need Help To Generate Result In Table By 'Php'

  • robin_ny4u
  • Born
  • Born
  • robin_ny4u
  • Posts: 2

Post 3+ Months Ago

Hello Friends... This is my very first posting on a forum world.

Please help me to solve out the problem m facing from last 10 days.

Friends I have a database in MySQL and wanna generate result according to student's scholar no. and show that result in HTML table. The requirement is when student want to get his/her result, can enter his Scholar No. in Text Box on Form and after submit he will get result for various exams.

:oops: :oops: :oops:

The Table Structure for Result is as under :


Code: [ Select ]
CREATE TABLE IF NOT EXISTS `result` (
  `R_No` mediumint(5) NOT NULL,
  `Sch_No` mediumint(5) NOT NULL,
  `Class` varchar(5) NOT NULL,
  `Name` varchar(60) NOT NULL,
  `Test_Name` varchar(10) NOT NULL,
  `Week` varchar(5) NOT NULL,
  `English` decimal(5,2) NOT NULL,
  `Hindi` decimal(5,2) NOT NULL,
  `Maths` decimal(5,2) NOT NULL,
  `GSC` decimal(5,2) NOT NULL,
  `SSC` decimal(5,2) NOT NULL,
  `Total` decimal(5,2) NOT NULL,
  `Per` decimal(5,2) NOT NULL,
  `Rank` decimal(5,2) NOT NULL,
  `History` decimal(5,2) NOT NULL,
  `Geography` decimal(5,2) NOT NULL,
  `Economics` decimal(5,2) NOT NULL,
  `Physics` decimal(5,2) NOT NULL,
  `Chemistry` decimal(5,2) NOT NULL,
  `Biology` decimal(5,2) NOT NULL,
  `Civics` decimal(5,2) NOT NULL,
  `Obj` decimal(5,2) NOT NULL,
  `Result_10_ID` mediumint(9) NOT NULL auto_increment,
  PRIMARY KEY  (`Result_10_ID`)
) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=112 ;
  1. CREATE TABLE IF NOT EXISTS `result` (
  2.   `R_No` mediumint(5) NOT NULL,
  3.   `Sch_No` mediumint(5) NOT NULL,
  4.   `Class` varchar(5) NOT NULL,
  5.   `Name` varchar(60) NOT NULL,
  6.   `Test_Name` varchar(10) NOT NULL,
  7.   `Week` varchar(5) NOT NULL,
  8.   `English` decimal(5,2) NOT NULL,
  9.   `Hindi` decimal(5,2) NOT NULL,
  10.   `Maths` decimal(5,2) NOT NULL,
  11.   `GSC` decimal(5,2) NOT NULL,
  12.   `SSC` decimal(5,2) NOT NULL,
  13.   `Total` decimal(5,2) NOT NULL,
  14.   `Per` decimal(5,2) NOT NULL,
  15.   `Rank` decimal(5,2) NOT NULL,
  16.   `History` decimal(5,2) NOT NULL,
  17.   `Geography` decimal(5,2) NOT NULL,
  18.   `Economics` decimal(5,2) NOT NULL,
  19.   `Physics` decimal(5,2) NOT NULL,
  20.   `Chemistry` decimal(5,2) NOT NULL,
  21.   `Biology` decimal(5,2) NOT NULL,
  22.   `Civics` decimal(5,2) NOT NULL,
  23.   `Obj` decimal(5,2) NOT NULL,
  24.   `Result_10_ID` mediumint(9) NOT NULL auto_increment,
  25.   PRIMARY KEY  (`Result_10_ID`)
  26. ) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=112 ;



and the Data that contained in the above table is as under:-


Code: [ Select ]
INSERT INTO `result` (`R_No`, `Sch_No`, `Class`, `Name`, `Test_Name`, `Week`, `English`, `Hindi`, `Maths`, `GSC`, `SSC`, `Total`, `Per`, `Rank`, `History`, `Geography`, `Economics`, `Physics`, `Chemistry`, `Biology`, `Civics`, `Obj`, `Result_10_ID`) VALUES
(1, 3301, '10 G', 'ROHIT SANDAL', 'MT1', '', 7.50, 11.50, 10.00, 0.00, 0.00, 0.00, 0.00, 0.00, 2.75, 2.50, 3.25, 2.00, 3.25, 3.25, 2.50, 20.00, 1),
(2, 3302, '10 G', 'RUBINA GODARA', 'MT1', '', 8.00, 11.00, 10.00, 0.00, 0.00, 0.00, 0.00, 0.00, 3.00, 1.00, 2.25, 1.00, 1.75, 2.00, 2.25, 21.00, 2),
(3, 3303, '10 G', 'SAMEEKSHA KATHURIA', 'MT1', '', 11.50, 18.75, 23.00, 0.00, 0.00, 0.00, 0.00, 0.00, 3.00, 2.75, 1.75, 4.00, 3.50, 4.25, 3.50, 20.00, 3),
(1, 3301, '10 G', 'ROHIT SANDAL', '1-TERM', '', 22.50, 36.00, 18.50, 45.50, 2.50, 0.00, 0.00, 0.00, 14.25, 9.00, 15.50, 23.00, 10.50, 16.50, 12.00, 20.00, 38),
(2, 3302, '10 G', 'RUBINA GODARA', '1-TERM', '', 27.25, 49.25, 7.00, 14.00, 2.00, 0.00, 0.00, 0.00, 15.00, 12.75, 15.50, 24.75, 14.50, 19.00, 13.25, 21.00, 39),
(3, 3303, '10 G', 'SAMEEKSHA KATHURIA', '1-TERM', '', 50.00, 52.00, 70.50, 63.00, 15.50, 0.00, 0.00, 0.00, 17.00, 20.00, 23.75, 32.50, 20.50, 24.25, 31.25, 27.00, 40),
(1, 3301, '10 G', 'ROHIT SANDAL', '2-TERM', '', 22.50, 36.00, 18.50, 45.50, 2.50, 0.00, 0.00, 0.00, 14.25, 9.00, 15.50, 23.00, 10.50, 16.50, 12.00, 20.00, 75),
(2, 3302, '10 G', 'RUBINA GODARA', '2-TERM', '', 27.25, 49.25, 7.00, 14.00, 2.00, 0.00, 0.00, 0.00, 15.00, 12.75, 15.50, 24.75, 14.50, 19.00, 13.25, 21.00, 76),
(3, 3303, '10 G', 'SAMEEKSHA KATHURIA', '2-TERM', '', 50.00, 52.00, 70.50, 63.00, 15.50, 0.00, 0.00, 0.00, 17.00, 20.00, 23.75, 32.50, 20.50, 24.25, 31.25, 27.00, 77);
  1. INSERT INTO `result` (`R_No`, `Sch_No`, `Class`, `Name`, `Test_Name`, `Week`, `English`, `Hindi`, `Maths`, `GSC`, `SSC`, `Total`, `Per`, `Rank`, `History`, `Geography`, `Economics`, `Physics`, `Chemistry`, `Biology`, `Civics`, `Obj`, `Result_10_ID`) VALUES
  2. (1, 3301, '10 G', 'ROHIT SANDAL', 'MT1', '', 7.50, 11.50, 10.00, 0.00, 0.00, 0.00, 0.00, 0.00, 2.75, 2.50, 3.25, 2.00, 3.25, 3.25, 2.50, 20.00, 1),
  3. (2, 3302, '10 G', 'RUBINA GODARA', 'MT1', '', 8.00, 11.00, 10.00, 0.00, 0.00, 0.00, 0.00, 0.00, 3.00, 1.00, 2.25, 1.00, 1.75, 2.00, 2.25, 21.00, 2),
  4. (3, 3303, '10 G', 'SAMEEKSHA KATHURIA', 'MT1', '', 11.50, 18.75, 23.00, 0.00, 0.00, 0.00, 0.00, 0.00, 3.00, 2.75, 1.75, 4.00, 3.50, 4.25, 3.50, 20.00, 3),
  5. (1, 3301, '10 G', 'ROHIT SANDAL', '1-TERM', '', 22.50, 36.00, 18.50, 45.50, 2.50, 0.00, 0.00, 0.00, 14.25, 9.00, 15.50, 23.00, 10.50, 16.50, 12.00, 20.00, 38),
  6. (2, 3302, '10 G', 'RUBINA GODARA', '1-TERM', '', 27.25, 49.25, 7.00, 14.00, 2.00, 0.00, 0.00, 0.00, 15.00, 12.75, 15.50, 24.75, 14.50, 19.00, 13.25, 21.00, 39),
  7. (3, 3303, '10 G', 'SAMEEKSHA KATHURIA', '1-TERM', '', 50.00, 52.00, 70.50, 63.00, 15.50, 0.00, 0.00, 0.00, 17.00, 20.00, 23.75, 32.50, 20.50, 24.25, 31.25, 27.00, 40),
  8. (1, 3301, '10 G', 'ROHIT SANDAL', '2-TERM', '', 22.50, 36.00, 18.50, 45.50, 2.50, 0.00, 0.00, 0.00, 14.25, 9.00, 15.50, 23.00, 10.50, 16.50, 12.00, 20.00, 75),
  9. (2, 3302, '10 G', 'RUBINA GODARA', '2-TERM', '', 27.25, 49.25, 7.00, 14.00, 2.00, 0.00, 0.00, 0.00, 15.00, 12.75, 15.50, 24.75, 14.50, 19.00, 13.25, 21.00, 76),
  10. (3, 3303, '10 G', 'SAMEEKSHA KATHURIA', '2-TERM', '', 50.00, 52.00, 70.50, 63.00, 15.50, 0.00, 0.00, 0.00, 17.00, 20.00, 23.75, 32.50, 20.50, 24.25, 31.25, 27.00, 77);



As the above table structure is fixed as per requirement, I can't change a single field, the required result is as mentioned below (Result Structured Required)

:oops:

Attachments:
table.jpg


Please Help me to figure out the required result...

Warm Regards To Each n Every Helper...
Niranjan :D
Moderator Remark: Added [code] tags. Image did not work either, fixed that for you.
  • Anonymous
  • Bot
  • No Avatar
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post 3+ Months Ago

  • Bigwebmaster
  • Site Admin
  • Site Admin
  • User avatar
  • Posts: 9090
  • Loc: Seattle, WA & Phoenix, AZ

Post 3+ Months Ago

I would think an SQL statement similiar to the following would work:

Code: [ Select ]
SELECT English, Hindi, Maths, GSC, SSC, History, Geography, Economics, Physics, Chemistry, Biology, Civics, Obj, Test_Name, Total
WHERE Sch_No = SOMEVALUE;
  1. SELECT English, Hindi, Maths, GSC, SSC, History, Geography, Economics, Physics, Chemistry, Biology, Civics, Obj, Test_Name, Total
  2. WHERE Sch_No = SOMEVALUE;


The SOMEVALUE would be replaced in your PHP code with a PHP variable. Since the data you have shown above has each student in there 3 times (each student has their own Sch_No), that query above would return three results. You would simply take those results and make the three columns in the table using a PHP loop to output the results. Shouldn't be that hard if you think it through. Hope that helps!

Also I have a feeling the above is for a school work assignment. Nobody is going to probably give you an exact answer for this, but we are willing to help you with your questions to work your way through it. Which part are you having trouble with if the above did not help?
  • robin_ny4u
  • Born
  • Born
  • robin_ny4u
  • Posts: 2

Post 3+ Months Ago

[quote="Bigwebmaster"] First of all I would like to thank you for quicker reply... As I amazzed about reply... Its very very quick.. Thanks again...

Now I came to the topic.. As you suggest me the query.. I would like to tell that my logic about SQL query is fine... I have that query in my code.. 3 rows that comes in result has marks for each type of Test (exam), its called Monday Test, Term - 1 and Term - 2 and so on upto 10 level. But I m very beginner in Php, so can't get result in above mentioned format, I don't have any idea how to use loop in Php.

I would be very thankful to you, if you please write code for the problem described above..

Please Help Me

Regards
Niranjan
  • devilwood
  • Silver Member
  • Silver Member
  • User avatar
  • Posts: 436

Post 3+ Months Ago

Code: [ Select ]
 
<?php
 
$query = "SELECT * FROM results WHERE Sch_No = SOMENUMBER";
 
// call query
$results = mysql_query($query);
 
// loop thru and get results into an array called $row[]
 
while ($row = mysql_fetch_array($results)) {
 
// assign a variable to each row being extracted for the individual
$scholarnumber = $row['Sch_No']
$myclass = $row['Class'];
$name = $row['Name'];
$testname = $row['Test_Name'];
 
 
//display user data
echo "<table><tr><td>$scholarnumber</td><td>$myclass</td><td>$name</td></tr></table>";
 
 
}
 
 
  1.  
  2. <?php
  3.  
  4. $query = "SELECT * FROM results WHERE Sch_No = SOMENUMBER";
  5.  
  6. // call query
  7. $results = mysql_query($query);
  8.  
  9. // loop thru and get results into an array called $row[]
  10.  
  11. while ($row = mysql_fetch_array($results)) {
  12.  
  13. // assign a variable to each row being extracted for the individual
  14. $scholarnumber = $row['Sch_No']
  15. $myclass = $row['Class'];
  16. $name = $row['Name'];
  17. $testname = $row['Test_Name'];
  18.  
  19.  
  20. //display user data
  21. echo "<table><tr><td>$scholarnumber</td><td>$myclass</td><td>$name</td></tr></table>";
  22.  
  23.  
  24. }
  25.  
  26.  



There's how you loop through results in php, but it's still going to take some work with your query and displaying your results. You may need to add rows together like if you wanted to add all scores for English test you could do it right in the 'while' loop by using += this will add all the English scores together.

Code: [ Select ]
 
 
$english_total_score += $row['English'];
 
 
  1.  
  2.  
  3. $english_total_score += $row['English'];
  4.  
  5.  

Post Information

  • Total Posts in this topic: 4 posts
  • Users browsing this forum: No registered users and 68 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
cron
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.