Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / New
Stats: 3,154,755 members, 7,824,165 topics. Date: Saturday, 11 May 2024 at 01:58 AM

How To Add Up Tables Using Php - Programming - Nairaland

Nairaland Forum / Science/Technology / Programming / How To Add Up Tables Using Php (1317 Views)

How To Arrange School Broadsheet Sheet From Mysql Tables / Nairaland Uses Tables!! / What Do You Think About Using PHP For Software Development (2) (3) (4)

(1) (Reply) (Go Down)

How To Add Up Tables Using Php by Kancybernet: 2:04am On Dec 09, 2017
Good Morning nairalanders. Please i have an issue i would really like Php programmers to help me in resolving. Am working on a school management system at the office.. After completing the project, it turns out that i ought to create a space on the result sheet for Highest Mark, and Lowest Mark and Grade. I have the exam result and CA on different tables in the database. I want to join this tables, add up each student score (over 100) and compare which of the student scored highest and lowest on each subject.. Please i will really appreciate if you guys can guide me through, using Php. I already tried while loop, but ran into some issues especially when trying to compare the results and display the highest score. it keeps bringing out list of numbers. Below is a sample of the experiment am trying to work out from. I doubt if its result is reasonable though as i have altered it beyond recognition out of frustration.. Thanks guys..


<?php
require_once("database.php"wink;
$usid="uj@k.c";

$select=mysqli_query($mysqli,"SELECT * FROM `exam_result` "wink or die(mysqli_error($mysqli));

if($select==true)
{
while($array=mysqli_fetch_array($select))
{
$total2=$array['English'] + $array['maths'];

}
$select2= mysqli_query($mysqli,"SELECT * FROM `ca_result` "wink or die(mysqli_error($mysqli));

if($select2 ==true)
{
while($array2=mysqli_fetch_array($select2))
{

$all=array_shift(array_slice($array2, 0, 1));
echo $total=$all['sn'];

//$value2=$value['$total'];


//break;

//echo $total2."<br>";


//$value=current($array2);
//echo $value."<br>";


}

}}
//echo $total2."<br>";
//echo $total2['sn'];



?>
Re: How To Add Up Tables Using Php by trytillmake(m): 12:30pm On Dec 09, 2017
Work harder on it u will get it, is it that u wanna join tables then use join query; check w3 schools, been long i handled php but perseverance is key. Keep it up

1 Like

Re: How To Add Up Tables Using Php by vankaid: 1:03pm On Dec 09, 2017
Kancybernet:
Good Morning nairalanders. Please i have an issue i would really like Php programmers to help me in resolving.
?>
Most times programming challenges are usually solved with an idea that is completely different from the perspective you are approaching it.

I do not know the full details of the CA and exam score tables so I cant help much.

How ever, have you thought about summing CAs and exam scores separately and saving each total in a variable which you can also add together.

i dont understand your situation properly so my advise might not make any sense.

Please provide more details.

1 Like

Re: How To Add Up Tables Using Php by Kancybernet: 12:55am On Dec 10, 2017
vankaid:

Most times programming challenges are usually solved with an idea that is completely different from the perspective you are approaching it.

I do not know the full details of the CA and exam score tables so I cant help much.

How ever, have you thought about summing CAs and exam scores separately and saving each total in a variable which you can also add together.

i dont understand your situation properly so my advise might not make any sense.

Please provide more details.

Attached are screenshot of the database... each row contains score of each student on different subjects.. There are records of different student in the class.. I want to sum each Ca score and exam for each subject for each student, and compare the total score of each student on a subject, for all student, and get the highest score in the class, for that subject..

Re: How To Add Up Tables Using Php by WebRabbi: 7:20pm On Dec 10, 2017
The best solution is to create a third table where you subject total score will be saved too.

Then you can use MySQL MAX(to query highest score) and MIN(to query lowest score).
Re: How To Add Up Tables Using Php by vankaid: 2:50am On Dec 11, 2017
Kancybernet:


Attached are screenshot of the database... each row contains score of each student on different subjects.. There are records of different student in the class.. I want to sum each Ca score and exam for each subject for each student, and compare the total score of each student on a subject, for all student, and get the highest score in the class, for that subject..

Please use the SQL below:

SELECT sum(eng) AS eng_total, sum(maths) AS maths_total
from
(
select *
from ca_result
union all
select *
from exam_result
) t
group by uid

However, the above query will work on 2 conditions:

1. that you have a unique key ( I assumed it to be uid in the query above even though it apears you have it as usid) identifying each student on both exam and ca tables.
2. that the columns selected on ca_result and exam_result tables in the sub query are equal

N.B: when i say sum(eng) or sum(maths) I assumed eng and maths to be a correct column name in the tables please use your actual table column names.

(1) (Reply)

13-year-old Gerald Has One Of The Largest Telegram & Whatsapp Channel & Groupâś” / Thread closed / Recommend A Laptop For Me Bw 50-60k

(Go Up)

Sections: politics (1) business autos (1) jobs (1) career education (1) romance computers phones travel sports fashion health
religion celebs tv-movies music-radio literature webmasters programming techmarket

Links: (1) (2) (3) (4) (5) (6) (7) (8) (9) (10)

Nairaland - Copyright © 2005 - 2024 Oluwaseun Osewa. All rights reserved. See How To Advertise. 18
Disclaimer: Every Nairaland member is solely responsible for anything that he/she posts or uploads on Nairaland.