Question:
PHP/SQL Question: I have 3 values entered into a database from a form, I am adding these values 2gether in php?
?
2010-04-23 05:13:17 UTC
and I need to print out the biggest sum of these values together. Some code below:
$fname = $_POST['fname'];
$surname = $_POST['surname'];
$student_number = $_POST['student_number'];
$exam = $_POST['exam'];
$project = $_POST['project'];
$participation = $_POST['participation'];
$totalmark = $exam + $project + $participation;
$sqlquery = "INSERT INTO details VALUES ('$fname', '$surname', '$student_number', '$exam', '$project', '$participation')";
$results = mysql_query($sqlquery);

Im not sure what to do next. I thought I could do the following:
if
max $totalmark
{
echo "Highest grade is" . $totalmark;
}

but that wouldnt work as it wont give highest grade from all the values in the database.
Any ideas??? thanks.
Three answers:
TheMadProfessor
2010-04-23 07:37:33 UTC
The above responder has the right idea, but there's no reason to actually store derived data...just create it on the fly as follows:



SELECT MAX(totalmark) FROM

(SELECT exam + project + participation AS totalmark FROM details)



If you really want to access this frequently without redoing the subselect every time, you could create a view (a virtual table) with the totalmark column and any other info desired.



Edit: You only want one set of quotes...the entire string of SQL constitutes your query, as in:



$sqlquery2 = "SELECT MAX(totalmark) FROM (SELECT exam + project + participation AS totalmark FROM details)";
Nobody
2010-04-23 05:18:59 UTC
Just insert the $totalmark into the database and then run the following query:



SELECT MAX (totalmark) AS 'Total Mark' FROM details;



Simple as pie!
2016-11-01 08:18:03 UTC
i do no longer many times answer this variety of a Q, by using fact it particularly is in basic terms too risky and too open to easily undeniable visciousness. yet God positioned it on my heart to respond to right here. and that i'm in settlement. yet something got here approximately to me: particularly, most of the 'regulations' have no longer something to do with Christianity. They have been set down long earlier Jesus walked. no longer killing no longer mendacity no longer stealing no longer plotting The sacredness and honoring of relatives (father, mom, husband, spouse) etc. And the notice God, interprets to all languages and thought platforms of religion, it would not characterize a 'Christian' strategies-set (oh i comprehend there are people who like to argue and debate - yet, please, get the better image right here). as quickly as lower back, people choose to concentration rage & concern and take it out in this group or that group. it particularly is a found out societal habit we bypass on era to era (and activities arenas are large places to start to foment this variety of crowd separation) seems to me, that it appears that evidently that in case you pick something performed politically, get the main funds mutually you are able to with the main linked people you are able to and there you have it - a regulation. regulations many times come AFTER no longer earlier - regulations are additionally used to fulfill agendas. So BLAMING everybody for something is stupid. i've got have been given to take duty for my strategies, my motives, my intentions, my strikes and the impression my strikes, strategies, motives and intentions have on the gang of humanity as an entire. If all of us did this with somewhat extra self-discipline, there could be a large shift, with little to no attempt, and Qs like those would not be needed. sure needed - maximum in basic terms choose to no longer think of deeply, yet spout off the 1st rabble rousing difficulty that includes strategies and particularly think of it particularly is the certainty on the middle of their being. it particularly is exactly my opinion. Thumbs down have not have been given any impression on me. Reporting this has no impression on me. So have at it, and mutually as you're at it, have a marvelous God-crammed day (what you think of roughly it or do with it particularly is not my concern - i'm in basic terms letting you have it) Peace be to us all and that i assume Charles Dickens grow to be purely a terrible author whilst he had Tiny Tim "God Bless Us All"..... thank you for the Q i presumed i could on no account answer :)


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...