PHP - Problem On Where I Want To Display My Calculation And Other Variables
This code was given to me by mjdamato to help display a student and the course that student has take and within that the modules in the course and the sessions in course including module mark and grade and student's session marks and grades. I am very weak on php code as I have only done it once and that was following a php workbook 2 years ago. I am more of a database specialist. Below is the code given to me and you can also download the code from the attachment:
Code: [Select] <?php function outputModule($moduleID, $moduleName, $sessionData) { if(!count($sessionData)) { return false; } $markTotal = 0; $markGrade = 0; $weightSession = 0; $grade = ""; $sessionsHTML = ""; foreach($sessionData as $session) { $sessionsHTML .= "<p><strong>Session:</strong> {$session['SessionId']} <br><strong>Session Mark:</strong> {$session['Mark']}</strong> <br><strong>Session Weight Contribution</strong> {$session['SessionWeight']}%</p>\n"; $markTotal += round($session['Mark'] / 100 * $session['SessionWeight']); $weightSession += ($session['SessionWeight']); $markGrade = round($markTotal / $weightSession * 100); if ($markGrade >= 70){ $grade = "A";} else if ($markGrade >= 60 && $markGrade <= 69){ $grade = "B";} else if ($markGrade >= 50 && $markGrade <= 59){ $grade = "C";} else if ($markGrade >= 40 && $markGrade <= 49){ $grade = "D";} else if ($markGrade >= 30 && $markGrade <= 39){ $grade = "E";} else if ($markGrade >= 0 && $markGrade <= 29){ $grade = "F";} } $moduleHTML = "<p><br><strong>Module:</strong> {$moduleID} - {$moduleName} <br><strong>Module Mark:</strong> {$markTotal} <br><strong>Mark Percentage:</strong> {$markGrade} <br><strong>Grade:</strong> {$grade} </p>\n"; return $moduleHTML . $sessionsHTML; } $output = ""; $studentId = false; $courseId = false; $moduleId = false; while ($row = mysql_fetch_array($result)) { if($studentId != $row['StudentUsername']) { //Student has changed $studentId = $row['StudentUsername']; $output .= "<p><strong>Student:</strong> {$row['StudentForename']} {$row['StudentSurname']} ({$row['StudentUsername']})\n"; } if($courseId != $row['CourseId']) { //Course has changed $courseId = $row['CourseId']; $output .= "<br><strong>Course:</strong> {$row['CourseId']} - {$row['CourseName']} <strong>Course Mark</strong> <strong>Grade</strong> <br><strong>Year:</strong> {$row['Year']}</p>\n"; } if($moduleId != $row['ModuleId']) { //Module has changed if(isset($sessionsAry)) //Don't run function for first record { //Get output for last module and sessions $output .= outputModule($moduleId, $moduleName, $sessionsAry); } //Reset sessions data array and Set values for new module $sessionsAry = array(); $moduleId = $row['ModuleId']; $moduleName = $row['ModuleName']; } //Add session data to array for current module $sessionsAry[] = array('SessionId'=>$row['SessionId'], 'Mark'=>$row['Mark'], 'SessionWeight'=>$row['SessionWeight']); } //Get output for last module $output .= outputModule($moduleId, $moduleName, $sessionsAry); //Display the output echo $output; } } ?> Below the what this code outputs: Student: Mayur Patel (u0867587) Course: INFO101 - Bsc Information Communication Technology Course Mark Year: 3 Module: CHI2550 - Modern Database Applications Module Mark: 41 Mark Percentage: 68 Grade: B Session: AAB Session Mark: 72 Session Weight Contribution 20% Session: AAE Session Mark: 67 Session Weight Contribution 40% Module: CHI2513 - Systems Strategy Module Mark: 31 Mark Percentage: 62 Grade: B Session: AAD Session Mark: 61 Session Weight Contribution 50% If you look above it shows that there is nothing in the Course Mark: section, what Course Mark is suppose to do is total up all the module mark percentages and then divide it by the number of modules. So the calculation will be adding up all the Code: [Select] $markGrade and dividing it by count Code: [Select] $ModuleID. In examle above it will be 68 (mark percentage for 1st module) + 62 (mark percentage for 2nd module) / 2 (number of modules in the course). So the Course Mark should equal 65. The problem is that all of the calculations are in the foreach loop but where the course details and where the course marks are going to be placed are in the while loop. So the problem is that if the total Course Mark (lets say we call in $totalCourse) is displayed in the while loop it will provide an undifined index as the calculation will be placed with the other calculations in the foreach loop which is outside the while loop, if I do the calculation with in the while loop, it will only choose the 1st module mark percentage and divdie it by the first module only, this is obviously incorrect as it sohuld try and do this for all modules hence why my calculations are in the foreach loop which does this. So how will change the code so that the course details can go from the while loop and be placed in the foreach loop so then I can include the calculation in the foreach loop. Thank You and hopefully you understand it, just read it very carefully to understand it, it is very simple what I want to achieve but I do not know how to do it. [attachment deleted by admin] Similar TutorialsHi Guys, i am trying to get my head around doing a calculation for the total and getting the discount from each row and display the total. I am using both mySql and php. How do i get the TOTAL BALANCE (this is = total balance - the discount) and the TOTAL PAYMENT DUE (this is = TOTAL CLIENT PAYMENT - TOTAL BALANCE). Please note that the discount settings are different for each row and there are an number of different rows. The table is as follows: Code: [Select] `invoiceID` int(11) NOT NULL AUTO_INCREMENT, `USERID` varchar(255) NOT NULL DEFAULT '', `CLIENTID` varchar(150) NOT NULL DEFAULT '', `amount` decimal(10,2) NOT NULL DEFAULT '0.00', `Discount` double(4,2) NOT NULL DEFAULT '0.00' The page code is as follows: <?php $query = "SELECT ID FROM clients WHERE username = '$u'"; $result = mysql_query($query); if(mysql_num_rows($result)) { while($row = mysql_fetch_assoc($result)){ $USERID = $row['ID']; $client = mysql_real_escape_string($_GET['id']); $query = "SELECT * FROM payment WHERE USERID = '$USERID' AND CLIENTID = '$client'"; $result = mysql_query($query); $num=mysql_numrows($result); ?> <table> <thead><tr> <th>Invoice ID</th> <th>Discount</th> <th>Cost</th> <th>Balance</th> </tr> </thead> <tbody> <?php $i=0; while ($i < $num) { $invoiceID=mysql_result($result,$i,"invoiceID"); $USERID=mysql_result($result,$i,"USERID"); $CLIENTID=mysql_result($result,$i,"CLIENTID"); $amount=mysql_result($result,$i,"amount"); $Discount=mysql_result($result,$i,"Discount"); $balance = $amount - (($amount/100)*$Discount); ?> <tr> <td><?php echo $invoiceID; ?></td> <td><?php echo $Discount; ?></td> <td><?php echo $amount; ?></td> <td><?php echo number_format($balance,2); ?></td> </tr> <?php $i++; } } } $CLIENTID = mysql_real_escape_string($_GET['id']); $USERID = mysql_real_escape_string($_GET['USERID']); $sql = "SELECT SUM(amount) AS TOTALPAYMENT FROM payment WHERE CLIENTID = '".$_GET['id']."' AND USERID = '".$_GET['USERID']."'" ; $resulte = mysql_query($sql); mysql_close(); if(mysql_num_rows($resulte)) { while($row = mysql_fetch_assoc($resulte)){ $amount = $row['amount']; $Discount = $row['Discount']; $totalPayment = $row['TOTALPAYMENT']; $balance = $amount - (($amount/100)*$Discount); ?> </tbody><tfoot> <tr><td></td></tr> </tfoot> </table> <table> <tbody> <tr> <td>Total Client Payment:</td> <td><?php echo number_format($totalPayment,2); ?></td> </tr> <tr> <td>Total Balance:</td> <td><?php echo number_format($balance,2); ?></td> </tr> <tr> <td>Total Payment due:</td> <td><?php echo ""; ?></td> </tr></tbody></table> <?php } } ?> I forgot to note that the TOTAL BALANCE calculation is not correct. Any help would be appreciated. This is a bit of a puzzle. Look at the sum and result below: Code: [Select] $markTotal += ($session['Mark'] / 100 * $session['SessionWeight']); Result on Browser with explanation to help you: Module: CHI2550 - Modern Database Applications 35% (this is $markTotal) ... This is where I want add the total mark for 100% Session: AAB 100% (this is $session['Mark']) 10% (this is $session['SessionWeight']) Session: AAE 50% (this is $session['Mark']) 50% (this is $session['SessionWeight']) All percentage marks above are just add ons. As you can see the answer to the calculation above is right, the answer is 35 as it adds up the two session marks, divide by 100 and then times it by the total amount of the percentage. But I want to include a total mark where except it is out of the total session percentage (60% for above example as one Session is 40% and the other is 20%), it is out of a 100% but I can not work as simple as that as in above example one session is worth more than other. The total mark out of 100% of the above example should be 65%, but how do I achieve this in my calculation. It is not as simple as dividing the $session['Mark'] because one session is worth more than the other. So the above example will have 2 marks: one mark out of total percentage of the Sessions which for the above example is 35% and second mark is out of the full 100% of the module which is 65%. Thank you and any help is much appreciated Hi, I have a calculation issue in my php. Below is my code: Code: [Select] $output = ""; $studentId = false; $courseId = false; $moduleId = false; while ($row = mysql_fetch_array($result)){ $moduletotal += $row['Mark']; $modulemark = (int)($moduletotal); //Above here is the calculation for add in the Marks of all the sessions //Below is the code of the display of the query output if($studentId != $row['StudentUsername']) { $studentId = $row['StudentUsername']; $output .= "<p><strong>Student:</strong> {$row['StudentForename']} {$row['StudentSurname']} ({$row['StudentUsername']})"; } if($courseId != $row['CourseId']) { $courseId = $row['CourseId']; $output .= "<br><strong>Course:</strong> {$row['CourseId']} - {$row['CourseName']} <br><strong>Year:</strong> {$row['Year']}</p>"; } if($moduleId != $row['ModuleId']) { $moduleId = $row['ModuleId']; $output .= "<p><br><strong>Module:</strong> {$row['ModuleId']} - {$row['ModuleName']} $modulemark</p>"; } $output .= "<p><strong>Session:</strong> {$row['SessionId']} {$row['Mark']}</p>"; } Student: Mayur Patel (u0867587) Course: INFO101 - Bsc Information Communication Technology Year: 3 Module: CHI2550 - Modern Database Applications 72 (72 is the answer to the calculation for the first module but this is incorrect at it should also add the 67 and thus become 139) Session: AAB 72 Session: AAE 67 Module: CHI2513 - Systems Strategy 200 (200 is the answer to the calculation for this module but this is incorrect it should be only 61. But what it has done is that it has added the 72 and 67 from the first module and added it with the 61 in this module) Session: AAD 61 SO WHAT MY QUESTION IS THAT HOW CAN I FIND THE TOTAL OF EACH MODULE MARK WHICH THE VARIABLE $modulemark = (int)($moduletotal); IS TRYING TO DO BY ADDING UP ALL THE SESSIONS MARKS WITHIN EACH MODULE. I HAVE TRIED USING SUM(gr.Mark) in the query and using GROUP BY SessionId, ModuleId, StudentUsername, and CourseId but it ends up not being able to display any records. That is why I want to do the calculation using php rather than SQL. BELOW IS THE QUERY IF YOU WANT TO SEE IT: Code: [Select] $query = " SELECT st.CourseId, c.CourseName, st.Year, st.StudentUsername, st.StudentForename, st.StudentSurname, s.ModuleId, m.ModuleName, m.Credits, s.SessionId, s.SessionWeight, gr.Mark, gr.Grade FROM Course c INNER JOIN Student st ON c.CourseId = st.CourseId JOIN Grade_Report gr ON st.StudentId = gr.StudentId JOIN Session s ON gr.SessionId = s.SessionId JOIN Module m ON s.ModuleId = m.ModuleId WHERE (st.StudentUsername = '".mysql_real_escape_string($studentid)."') ORDER BY c.CourseName, st.StudentUsername, m.ModuleName, s.SessionId "; i am having issues getting the variables to show up on localhost server within the body element. is it something in the codes or something in the php.ini settings? here is some sample code Code: [Select] <h1>Skyward Aviation</h1> <h2>Contact Information</h2> <form action="ContactUpdate.php" method="get"> <table frame="border" rules="cols"> <colgroup width="50%" /> <colgroup width="50%" /> <tr> <td align="right" valign="top"> <p>First Name <input type="text" name="first_name" value="<?= $First ?>" size="36" /></p> <p>Last Name <input type="text" name="last_name" value="<?= $Last ?>" size="36" /></p> <p>Phone <input type="text" name="phone" value="<?= $Phone ?>" size="36" /></p> </td> <td align="right" valign="top"> <p>Address <input type="text" name="address" value="<?= $Address ?>" size="40" /></p> <p>City <input type="text" name="city" value="<?= $City ?>" size="10" /> State <input type="text" name="state" value="<?= $State ?>" size="2" maxlength="2" /> Zip <input type="text" name="zip" value="<?= $Zip ?>" size="10" maxlength="10" /></p> </td> </tr> </table> <p><input type="hidden" name="PHPSESSID" value='<?php echo session_id() ?>' /> <p><input type="submit" value="Submit" /></p> </form> In the page is shows <?= $First ?> in the area First Name textbox.
For debug purposes, I want to see all (each and every possible) variables from a website visitor, e.g. I know how to save the info in a database, I might even have the info emailed to myself, I just can't remember the "one-liner" I used to use to capture this info. Thank you in advance!
hello i have built a webpage using tables. i might have done something wrong (except using tables) and now the results are rendered chaotically on the webpage. also here is the attached file. after the 4th article it's all messy i have a solution but that means to insert a php tag inside another php tag, but won't work thankyou How would I output the value of a variable, getting the name from the value of another variable? For example: $var1 = 'var2'; $var2 = 'output'; I want it to return 'output', which I'd imagine would work through entering something along lines of $$var1; Does anyone know what I mean? I am having probelm in saving Session variables ALthough I'm writing session_start(); in the header of my php script and saving the values of Session array in the next page. It does not print the values or show right results. Code: [Select] session_start(); require_once ("functions.php"); $token=$_GET['t']; if(!isset($token)){ $name = stripslashes($_POST['username']); $email = stripslashes($_POST['email']); check_validate_input($name, $email); } if($token=='register') { show_registration_form(); } $my_model = new model(); $arr_info = $my_model->check_members($name,$email); if (($arr_info==NULL)&&($token!='register')) { echo '<p> Hello Guest</p><br />'; show_mailing_form(); } else if (($arr_info['role']=='user')||($arr_info['role'] == 'admin')) { $_SESSION['userId']=$arr_info['id']; $_SESSION['user_role']=$arr_info['role']; $_SESSION['user_name']=$arr_info['name']; print_r ($_SESSION);} here it does not print session array. $errors=0; //NEW USER NAME HAS BEEN SUBMITTED, CHECK IT OUT AND THEN ADD IF OKAY $newuser=$_REQUEST['newuser']; function TryAgain(){ global $errors; $errors++; echo '<br/><br/>Please try again <a href="index.php?locate=admin&sub=add_admin">here</a>'; echo "<br/>errors=[$errors]"; } echo "<br/>Trying to add user: $newuser<br/><br/>"; if ($newuser){ }else{ // field was left blank, report this to user and give them option to try again echo '<br/>Field was left empty, you must pick a username.';TryAgain(); } if (strlen($newuser)<5){echo 'Username should be at least 5 characters.';TryAgain();} if (!$errors){echo "continue to SQL [errors=$errors]";} what is wrong with this code? For some reason if I increment $errors with $errors++ within the function it doesn't increment outside the function's scope. even though I declare it as a global at the start of the function. I know I'm doing something stupid here but can somebody please tell me what it is? Thanks what is the problem in this code <div id="product"> <a class='inline' href="?prod=<?php echo $row['id'];?>#<?php echo $row['id']; ?>" > ..... </a> </div> <div style='display:none'> <div id='<?php echo $row['id'];?>'> .... </div> </div> $prod=$_GET['prod']; echo "the value of prod".$prod; $_SESSION['cart']=$prod; <script> $(document).ready(function(){ //Examples of how to assign the ColorBox event to elements $(".inline").colorbox({inline:true}); }); </script> Hi I have an infuriating problem which is stalling me with two large projects for a well known NGO right now. I am using mysqli and bound variables where the number of variables to bind is dependent on user input. I have a version of the code below working in php 5.2 but as of php 5.3 this method is no longer valid, specifically due to a change in the behavior of call_user_func_array with bound variables as arrays. I have read about this problem eslewhere but cannot get any of the workarounds to work with my example. Any help would be greatly appreciated. Code: [Select] # $parts is an array with variable number of values # $type is an array with variable number of values # $params is an array with variable number of values $query = 'SELECT SQL_CALC_FOUND_ROWS DISTINCT taxon.TaxonID, FROM taxon WHERE . join('', $parts) . " ORDER BY taxon.TaxonID"; # Prepare stmt if ($stmt = $mysqli->prepare($query)) { call_user_func_array (array($stmt, 'bind_param'),array_merge(array(join('', $type)), $params)); # execute $stmt->execute(); # bug info echo $stmt->errno, ':', $stmt->error; #store result $stmt->store_result(); # bind results $stmt->bind_result($ID); # fetch values while ($stmt->fetch()) { # results code goes here! } # free memory $stmt->free_result(); # close statement $stmt->close(); } Hello I first should say that I am a beginner. And actully friend was helping me with this but can't really contact him right now so I have to ask here. I have a php file where I have birthdate dropdown menu for month, day and a year and JS that just has all of the details about those 3 "variables" but the problem I am having is that this is inside submit form and whenever I or someone else submits this form and doesn't put any birthdate inside it doesn't show anything like "Please select your birthdate or something like that." and I honestly tried pretty much everything now but can' t get the answer on how to do that. Please help me. :( This topic has been moved to Third Party PHP Scripts. http://www.phpfreaks.com/forums/index.php?topic=315683.0 As the topic sais i have a problem trying to send variables to a javascript popup window, i think the problem is on line 38. I would very much appreciate some help Code: [Select] <html> <head> <script type="text/javascript"> function newPopup(url) { popupWindow = window.open(url,'popUpWindow','height=700,width=400,left=10,top=10,resizable=no,scrollbars=no,toolbar=yes,menubar=no,location=no,directories=no,status=yes') } </script> </head> <?php error_reporting(E_ALL); require_once 'GameQ.php'; $servers = array( 'server 1' => array('cs', 'd2o.warzone.nu', '27015'), 'server 2' => array('cs', 'd2o.warzone.nu', '27017'), 'server 3' => array('cs', 'wc3.warzone.nu', '27017'), 'server 4' => array('cs', 'aim.warzone.nu', '27015'), 'server 5' => array('cs', '83.255.249.204', '27025'), 'server 6' => array('tf2', 'tf2.warzone.nu', '27015'), 'server 7' => array('tf2', '83.255.249.200', '27015'), 'server 9' => array('cssource', 'css.warzone.nu', '27015'), 'server 10' => array('cssource', 'css.warzone.nu', '27017') ); $gq = new GameQ(); $gq->addServers($servers); $gq->setOption('timeout', 200); $gq->setFilter('normalise'); $gq->setFilter('sortplayers', 'gq_ping'); $results = $gq->requestData(); echo "<a href='steam://connect/d2o.warzone.nu:27015'>" . $results["server 1"]['gq_hostname'] . "</a><p>"; echo $results["server 1"]['gq_mapname'] . "<br>"; echo $results["server 1"]['gq_numplayers'] . "/" . $results["server 1"]['gq_maxplayers']; ?> // I think the problem is the line below this one <a href='JavaScript:newPopup("players.php?address=<?php echo="$results['server 1']['gq_address']"; ?>&port=<?php echo="$results['server 1']['gq_port']"; ?>");'> players online </a>"; <?php echo "<p><p>"; echo "<a href='steam://connect/d2o.warzone.nu:27017'>" . $results["server 2"]['gq_hostname'] . "</a><p>"; echo $results["server 2"]['gq_mapname'] . "<br>"; echo $results["server 2"]['gq_numplayers'] . "/" . $results["server 2"]['gq_maxplayers'] . " players online <p>"; echo "<p><p>"; echo "<a href='steam://connect/wc3.warzone.nu:27017'>" . $results["server 3"]['gq_hostname'] . "</a><p>"; echo $results["server 3"]['gq_mapname'] . "<br>"; echo $results["server 3"]['gq_numplayers'] . "/" . $results["server 3"]['gq_maxplayers'] . " players online <p>"; echo "<p><p>"; echo "<a href='steam://connect/aim.warzone.nu:27015'>" . $results["server 4"]['gq_hostname'] . "</a><p>"; echo $results["server 4"]['gq_mapname'] . "<br>"; echo $results["server 4"]['gq_numplayers'] . "/" . $results["server 4"]['gq_maxplayers'] . " players online <p>"; echo "<p><p>"; echo "<a href='steam://connect/83.255.249.204:27025'>" . $results["server 5"]['gq_hostname'] . "</a><p>"; echo $results["server 5"]['gq_mapname'] . "<br>"; echo $results["server 5"]['gq_numplayers'] . "/" . $results["server 5"]['gq_maxplayers'] . " players online <p>"; echo "<p><p>"; echo "<a href='steam://connect/tf2.warzone.nu:27015'>" . $results["server 6"]['gq_hostname'] . "</a><p>"; echo $results["server 6"]['gq_mapname'] . "<br>"; echo $results["server 6"]['gq_numplayers'] . "/" . $results["server 6"]['gq_maxplayers'] . " players online <p>"; echo "<p><p>"; echo "<a href='steam://connect/83.255.249.200:27015'>" . $results["server 7"]['gq_hostname'] . "</a><p>"; echo $results["server 7"]['gq_mapname'] . "<br>"; echo $results["server 7"]['gq_numplayers'] . "/" . $results["server 7"]['gq_maxplayers'] . " players online <p>"; echo "<p><p>"; echo "<a href='steam://connect/tf2.warzone.nu:27015'>" . $results["server 8"]['gq_hostname'] . "</a><p>"; echo $results["server 8"]['gq_mapname'] . "<br>"; echo $results["server 8"]['gq_numplayers'] . "/" . $results["server 8"]['gq_maxplayers'] . " players online <p>"; echo "<p><p>"; echo "<a href='steam://connect/css.warzone.nu:27015'>" . $results["server 9"]['gq_hostname'] . "</a><p>"; echo $results["server 9"]['gq_mapname'] . "<br>"; echo $results["server 9"]['gq_numplayers'] . "/" . $results["server 9"]['gq_maxplayers'] . " players online <p>"; echo "<p><p>"; echo "<a href='steam://connect/css.warzone.nu:27017'>" . $results["server 10"]['gq_hostname'] . "</a><p>"; echo $results["server 10"]['gq_mapname'] . "<br>"; echo $results["server 10"]['gq_numplayers'] . "/" . $results["server 10"]['gq_maxplayers'] . " players online <p>"; ?> </html> Hi, I have an itinerary form at http://www.happydaysremovals.com/estimate.html Customers fill this in, and it uses phpmailer-fe to email the results to myself. I use a HTML .tpl file so I can make the output email look as I want. All that is fine, but I would like a volume calculator. Next to each item on the form, the customer enters the amount of that item, usually 1 or 2. If it was say a setee, I want to define that a setee = 30 cubic feet, for example. Then I want the calculator to calculate the total cubic footage for all the variables, and include it in the html email. I know with javascript this can be done, but I was hoping for a PHP result and for it to somehow work in with phpmailer-fe, for example: </style> <script language="JavaScript"> function write_this() { var setteelarge; var setteemedium; var setteesmall; var setteelarge2; var setteemedium2; var setteesmall2; var setteelargeresult; var setteemediumresult; var setteesmallresult; var total; setteelarge = document.form1.LargeSettee.value; setteemedium = document.form1.MediumSettee.value; setteesmall = document.form1.SmallSettee.value; setteelarge2 = 45 setteemedium2 = 31 setteesmall2 = 22 setteelargeresult = (setteelarge * setteelarge2); setteemediumresult = (setteemedium * setteemedium2); setteesmallresult = (setteesmall * setteesmall2); total = (setteelargeresult+setteemediumresult+setteesmallresult) document.form1.Total_Cubic_Feet.value = total } </script> Basically, I want to be able to include the cubic feet total value to also be emailed to me in the HTML email, but preferably all in PHP. At the moment, I get everyones itinerary, but want to be automatically be able to work out the cubic footage. Thanks This is a bit of a puzzle. Look at the sum and result below: Code: [Select] $markTotal += ($session['Mark'] / 100 * $session['SessionWeight']); Result on Browser Module: CHI2550 - Modern Database Applications 41.2 (this is $markTotal) Session: AAB 72(this is $session['Mark']) 20% (this is $session['SessionWeight']) (The percentage signs are just add ons) Session: AAE 67(this is $session['Mark']) 40% (this is $session['SessionWeight']) As you can see the answer to the calculation above is right, the answer is 41 .2 as it adds up the two session marks, divide by 100 and then times it by the total amount of the percentage. But I want to include a total mark where except it is out of the total session percentage (60% for above example), it is out of a 100% but I can not work as simple as that as in above example one session is worth more than other. I have worked out that the answer for the total mark of the above example out of 100% should be 69, but how do I achieve this in my calculation. Thank you and any help is much appreciated So how Dear All, I am trying to fetch the sum of a column for current date and subtract a value from the sum for currently selected record. The query i build works fine in MySql but when the same query i placed in php no result it's blank. Below is the query.
<?php //Calculation for no of paxs. $query2=mysqli_query($con,"SELECT SUM(noopaxs-gattl) FROM tblsupvisitor where date(EnterDate) = CURDATE() || gst = 'INH' || gst = 'IN' GROUP BY confno"); $calc_no_paxs_for_today=mysqli_fetch_row($query2); $gattl=$calc_no_paxs_for_today['gattl']; ?>
and her is the assignment to the textbox.
<div class="row form-group"> <div class="col col-md-3"> <label for="textarea-input" style="color: purple" class=" form-control-label"><strong>Total No. Of Adults</strong></label> </div> <div class="col-12 col-md-9"> <input name="gattl" id="gattl" rows="9" class="form-control" required="" value="<?php echo $gattl;?>"> </div> </div>
Any help in this regard will be highly appreciated.
Kind Regards, Naveed. Hi, I have a calculation issue in my php. Below is my code: $ Code: [Select] moduletotal = 0; $modulecount = 0; $sessionweight = 0; while ($row = mysql_fetch_array($result)){ $moduletotal += $row['Mark']; $modulemark = (int)($moduletotal); // Here and above is the calculation which is simply adding the total number of marks // Below is the code that displays my results. The variable of the calculation is shown at the end of the last if statement (3rd one down) $output = ""; $studentId = false; $courseId = false; $moduleId = false; if($studentId != $row['StudentUsername']) { $studentId = $row['StudentUsername']; $output .= "<p><strong>Student:</strong> {$row['StudentForename']} {$row['StudentSurname']} ({$row['StudentUsername']})"; } if($courseId != $row['CourseId']) { $courseId = $row['CourseId']; $output .= "<br><strong>Course:</strong> {$row['CourseId']} - {$row['CourseName']} <br><strong>Year:</strong> {$row['Year']}</p>"; } if($moduleId != $row['ModuleId']) { $moduleId = $row['ModuleId']; $output .= "<p><br><strong>Module:</strong> {$row['ModuleId']} - {$row['ModuleName']} {$row['Credits']} $modulemark</p>"; } $output .= "<p><strong>Session:</strong> {$row['SessionId']} {$row['Mark']} {$row['Grade']} {$row['SessionWeight']}%</p>"; } echo $output; ?>The Results look like this at the moment (The answer the calculation is next to each Module): Student: Mayur Patel (u0867587) Course: INFO101 - Bsc Information Communication Technology Year: 3 Module: CHI2550 - Modern Database Applications 20 72 (72 is the answer to the calculation for the first module but this is incorrect at it should also add the 67 and thus become 139) Session: AAB 72 A 20% Session: AAE 67 B 40% Module: CHI2513 - Systems Strategy 20 200 (200 is the answer to the calculation for this module but this is incorrect it should be only 61. But what it has done is that it has added the 72 and 67 from the first module and added it with the 61 in this module) Session: AAD 61 B 50% SO WHAT MY QUESTION IS HOW CAN I GET THE CALCULATION SO THAT IT ONLY ADDS UP EACH SESSION MARKS THAT BELONGS TO A MODULE ONLY? IN THE EXAMPLE ABOVE IT SHOULD ONLY ADD THE MARKS FOR SESSION AAB AND AAE IN THE MODERN DATABASE APPLICATIONS MODULE AND THEN WHEN IT GETS TO THE NEXT MODULE WHICH IS SYSTEMS STRATEGY, THE MARKS FOR THAT MODULE SHOULD START AGAIN AND ADD ON THE MARKS FOR THE SESSION AAD IN THAT MODULE. HOPEFULLY YOU UNDERSTAND AND THANK YOU Below is the query if you want to look at it: Code: [Select] $query = " SELECT c.CourseName, st.CourseId, st.Year, st.StudentUsername, st.StudentForename, st.StudentSurname, s.ModuleId, s.SessionId, s.SessionWeight, gr.Mark, gr.Grade m.ModuleName, m.Credits, FROM Course c INNER JOIN Student st ON c.CourseId = st.CourseId JOIN Grade_Report gr ON st.StudentId = gr.StudentId JOIN Session s ON gr.SessionId = s.SessionId JOIN Module m ON s.ModuleId = m.ModuleId WHERE (st.StudentUsername = '".mysql_real_escape_string($studentid)."') ORDER BY c.CourseName, st.StudentUsername, m.ModuleName, s.SessionId "; Hey guys,
I have problem displaying some stuff from mysql.
Idea was that Order's have rows like - OrderID|CustomerID|OrderDesc
So when i run $checkIsHavingOrders = mysql_query("SELECT * FROM orders ORDER BY OrderID DESC limit 10 WHERE CustomerID = '$myID'");
it should print
OrderID|CustomerID|OrderDesc
1001|1|Skin
1021|1|Skin
1031|1|Skin
(I made up the numbers so you can get image of thing i am trying to do..)
Thanks for your time!
Hi, I have an attendance system that calculates time in and time out for each day. I have a db field with time datatype that stores the total time for one day, say for example for today the total is 7:15:00 (7 hours and fifteen minutes). i am making a report to show all attendance records for a week. I need to show total of hours a week which is around 35-40 hours so how can this be done? screenshot of what i have. Edited March 15, 2020 by ramiwahdan typo error |