PHP - Using Php To Calculate Difference.
Hey guys im stuck in a bind and need some input.
What im trying to do is display a number based from community levels. ex: This user need another 2 tasks to get next level. here are the levels 1- 0-2 task new 2- 2-5 tasks beginer 3- 5-7 tasks pro 4- 7+ tasks advanced The way it works is by two different tasks. basicly i wanna know which is the higher number in the tasks either how many posts or comment and figure out based on our levels how many tasks he need to complete in order for him to reach the next level. the first query sees how many post this user has the second check how many comment he has I wanna take the highest number and that belongs to whicheber catgory, do a calculation. and have this kind of output This user is level 2 and need 1 more task to reach the next level. Like i know if he need one more that he has 4 tasks done. I know im all over the place with this one im just trying to get someone who might have an idea of my issue and point me in the right direction. Either if this is a known ?? does this procedure has a specific name anything will help me. Similar TutorialsHello,
I want to calculate the difference between 2 textbox value live.
I found this solution for adding http://forums.phpfre...xt-box-values/ , but dont know how to convert this for subtracting
here is my form
echo '<tr><td></td><td style="text-align:center;">TOTAL</td><td style="text-align:center;"><input type="text" readonly="readonly" name="payamount" value='.$total.' style="text-align:center; font-weight:bold; font-size:13px;" ></td></tr>'; echo'<form name="form1" method="post" action="" > <tr><td></td><td style="text-align:center;">Advance</td><td style="text-align:center;"><input type="text" name="advance" ></td></tr> <tr><td></td><td style="text-align:center;">Discount</td><td style="text-align:center;"><input type="text" name="discount" ></td></tr> <tr><td></td><td style="text-align:center;">Total Payable</td><td style="text-align:center;"><input type="text" name="total" id="total"/></td></tr> <tr><td><input type="submit" name="submit" value="PAY NOW" >when i enter the value for advance and discount, it should subtract these values with Total and should get entered in Total Payable text box I have date stored in database in any of the given forms 2020-06-01, 2020-05-01 or 2019-04-01 I want to compare the old date with current date 2020-06-14 And the result should be in days. Any help please? PS: I want to do it on php side. but if its possible to do on database side (I am using myslq) please share both ways🙂 Edited June 14, 2020 by 684425I am wondering is it possible to calculate with an alphernumeric ID in PHP, can PHP basically make sense out of an ID like c04 ? I used such ID system for the category system because I was able to make more sense out of the c in front of the number, which is not necessarily needed. Would a SQL calculation like "$category_id + 1" work? Whereas $category_id stands for c04 and becomes a c05 after calculation. is it possible to calculate sum of the element in the array_pop . i have to get sum of 3 maximum subject with grade from student .
else if (($sub == 'BI') || ($sub == 'TSI') || ($sub == 'PAP') || ($sub == 'PAK')) { if ($res == 0) { $merit = 18; } if ($res == 1) { $merit = 16; } if ($res == 2) { $merit = 14; } if ($res == 3) { $merit = 12; } if ($res == 4) { $merit = 10; } if ($res == 5) { $merit = 8; } if ($res == 6) { $merit = 6; } if ($res == 7) { $merit = 4; } if ($res == 8) { $merit = 2; } if ($res == 9) { $merit = 0; } $main_add_merit1 = $merit; $main_add_merit1; $y[$i] = $main_add_merit1; //echo '<br>'; rsort($y); $first = array_pop($y); }
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 Hi, In Php , What is the different ebtween abc() and @abc() ??? Please advice . This is going to seem like a stupid question but I'm curious about it anyway. Isn't isset and !empty do the same? Considering security, is there a disadvantage in using $_REQUEST? Actually what's the difference between Code: [Select] if(...) and Code: [Select] if(isset(...) I am working with wordpress and I see a lot of "if" statements done like this if(condition): do something endif; I have always done it like so if(condition) { do something } what is the difference? does the first method have any advantages over the second method? I am having trouble getting this to work what am I doing wrong? <p class="tenTitle"><p class="tenTitle">Module 4i: Profit / Loss Forecast<br /> <?php // NAME STEP AND GIVE VALUE TO QUESTION VARIABLES SO ERROR CHECKING DOES NOT HAVE TO BE RECREATED FOR EVERY PAGE $stepNumber = '4i'; $numQuestions = '9'; //get values from the $_post array: $totalRev = $_POST['revenue']; echo "totalRev: ".$totalRev."<br />"; $vCost = $_POST['cost']; echo "vCost: ".$vCost."<br />"; $overheadCost = $_POST['overhead']; echo "overheadCost: ".$overheadCost."<br />"; $taxes = $_POST['taxes']; echo "taxes: ".$taxes."<br />"; $otherIncome = $_POST['other']; echo "other: ".$other."<br />"; //Calculate the gross profit: $gross = $totalRev - $vCost; echo "gross: ".$gross."<br />"; //Calculate the net profit: $netProfit = $gross - $overheadCost; echo "netProfit: ".$netProfit."<br />"; // Calculate Income after taxes: $afterTaxes = $netProfit - $taxes; echo "afterTaxes: ".$afterTaxes."<br />"; // Calculate the Total Income: $totalIncome = $afterTaxes + $otherIncome; echo "totalIncome: ".$TotalIncome."<br />"; // Print out the results print ' <table border="1" cellpadding="4" cellspacing="3" width="350"> <tr> <td align="left" valign="top" border="1"> Total Revenue</td><td><input type="text" style="40" name="totalRev" value="'.$totalRev.'"> </td> </tr> <tr> <td align="left" valign="top" border="1"> Less: Variable Cost</td><td><input type="text" style="40" name="vCost" value="'.$vCost.'"> </td> </tr> <tr> <td align="left" valign="top" border="1"> Gross profit</td><td><input type="text" style="40" name="grossProfit" value="'.$GrossProfit.'"> </td> </tr> <tr> <td align="left" valign="top" border="1"> Less: Overhead Cost</td><td> <input type="text" style="40" name="overhead" value="'.$overheadCost.'"> </td> </tr> <tr> <td align="left" valign="top" border="1"> Net Profit</td><td> <input type="text" style="40" name="netProfit" value="'.$netProfit.'"> </td> </tr> <tr> <td align="left" valign="top" border="1"> Taxes</td><td> <input type="text" style="40" name="taxes" value="'.$taxes.'"> </td> </tr> <tr> <td align="left" valign="top" border="1"> Profit After Taxes</td><td> <input type="text" style="40" name="profitAfterTaxes" value="'.$profitAfterTaxes.'"> </td> </tr> <tr> <td align="left" valign="top" border="1"> Other Income</td><td> <input type="text" style="40" name="otherIncome" value="'.$otherIncome.'"> </td> </tr> <tr> <td align="left" valign="top" border="1"> Net Income</td><td> <input type="text" style="40" name="netIncome" value="'.$netIncome.'"> </td> </tr> <tr> <td colspan="2" align="left" valign="top" border="1"> <input type="submit" name="submit" id="Submit" value="Calculate" /> </label></td> </tr> </table></form>'; // DEFINE SESSION VARIABLES $_SESSION['email']=$_POST['email']; $_SESSION['emailCc']=$_POST['emailCc']; $_SESSION['name']=$_POST['name']; // DEFINE VARIABLES FOR MAILING TO USER AND BUZGATE $to = 'askbuz@buzgate.org,'.$_POST['email']; $email_subject = "Step ".$stepNumber." in Buzgate's Five Step Program"; for ($i = 1; $i <= $numQuestions; $i++) { $eBodyQuestions .= $questions[$i]."\n" .$_POST['data'.$i]."\n"; } $email_body = $eBodyQuestions; $headers = "From:".$_POST['email']; //PLACE VARIABLES IN MAIL FUNCTION mail($to, $email_subject, $email_body, $headers); // DEFINE VARIABLES FOR MAILING TO USER AND BUZGATE $toCc = $_POST['emailCc']; $email_subjectCc = "Step ".$stepNumber." in Buzgate's Five Step Program from ".$_POST['name']; $email_bodyCc = $_POST['name']." has sent this to you from www.BUZGate.org/8.0/".$state_abbrv_low."/".$page_name."\n Please contact us at askbuz@buzgate.org if you have received this in error.\n"; $email_bodyCc = $email_bodyCc.$eBodyQuestions; $headersCc = "From:askbuz@buzgate.org"; //PLACE VARIABLES IN CC MAIL FUNCTION mail($toCc, $email_subjectCc, $email_bodyCc, $headersCc); // DISPLAY RESPONSE TO CORRECTLY FILLING OUT FORM echo "<p class='textCenter'>Thank you ".$_POST['name']." for completing Step ".$stepNumber."</p> <p class='textCenter'><a href='five_steps_4summary.html'>Click here</a> to continue to 4Summary</p> <p class='textCenter'>Or <a href='five_steps_".$stepNumber.".html'>try this form again</a>.</p>"; ?> hi all! i have 2 tables: PRODUCTS id_prod, id_cat, date, prod_name CATEGORIES id_cat, cat_name My goal is obtain the average (day and month) of all products inserted by users in this format: category Hardwa avg daily 20, month 100 category Components: avg daily 2, month 15 and so on. PS: the 'date' field is unix timestamp (int 10). Can you help me? I can't seem to figure out how to calculate the score the user gets when they hit the score button. I figured it would look something like this... $result_score = $right / 9 * 100.... but I've tried a few methods and I can't seem to figure out why its not working. Here is my code for the application.... Code: [Select] <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Multiplication Test</title> </head> <body> <?php require_once('database.php'); define ('ROWS', 3); define ('COLS', 3); define ('MAX_NUMBER', 12); date_default_timezone_set('America/New_York'); if (isset($_POST['btn_score'])) { $result_name= $_POST['result_name']; $result_score= $_POST['result_score']; $result_score = / 9 * 100; $sql = "INSERT INTO results (result_name, result_score, result_date_time) VALUES ('$result_name','$result_score', NOW());"; $db->exec($sql); //print_r ($_POST); $time1 = $_POST['ts']; $time1_object = new DateTime($time1); $now = new DateTime(); $time_span = $now->diff($time1_object); $minutes = $time_span->format('%i'); $seconds = $time_span->format('%s'); $seconds+= $minutes * 60; echo "It took $seconds seconds to complete the test<hr />"; foreach ($_POST as $problem => $answer) { if ($problem <> "btn_score" && $problem <> "ts") { //echo "$problem -- $answer <br />"; $problem = explode('_', $problem); $num1 = $problem[2]; $num2 = $problem[3]; $right = $num1 * $num2; if ($answer != $right) { echo "$num1 * $num2 = $answer , The right answer is $right<br />"; } } } } ?> <h1>Multiplication Test</h1> <form name="lab5" method="post" action="lab5b.php"> <?php $now = new DateTime(); //echo $now->format('Y-m-d H:i:s'); echo "<input type='hidden' name='ts' value='" . $now->format('Y-m-d H:i:s') . "'>"; ?> <table border="1" cellspacing="5" cellpadding="5"> <?php $no_of_problems = 0; for ($row=0; $row<ROWS; $row++) { echo "<tr>"; for ($col=0; $col<COLS; $col++) { $num1 = mt_rand(1,MAX_NUMBER); $num2 = mt_rand(1,MAX_NUMBER); echo "<td>$num1 * $num2 </td>"; echo "<td><input type='text' size='2' name=${no_of_problems}_mult_${num1}_${num2}></td>"; $no_of_problems++; } echo "</tr>"; } $colspan = 2 * COLS; echo "<tr><td colspan=$colspan align='right'><input type='submit' value='Score' name='btn_score'></td></tr>"; ?> </table> <br> <br> <label for="result_name">Student Name:</label> <input type="text" id="result_name" name="result_name" /><br /> </form> <br> <br> </body> </html> I have an array of appointment start times throughout a day. All appointments last 30 mins. I also have a list of times that staff are available to meet these appointment times (can be in any format, array etc.) I need to ensure the appointment times are fully covered by members of staff. E.g. Code: [Select] $appointmentStart[] = "09:30"; $appointmentStart[] = "10:00"; $appointmentStart[] = "11:00"; $appointmentStart[] = "12:30"; $appointmentStart[] = "13:30"; $appointmentStart[] = "15:00"; $appointmentStart[] = "17:00"; $staffMembers[] = "09:00*12:00"; $staffMembers[] = "13:00*16:00"; $staffMembers[] = "15:00*18:00"; In the above case, no, there are not enough staff members to cover this as nobody works from 12:00 to 13:00. I only really need a yes or no. Don't worry about staff breaks, they never work more than 3 hours each at a time. Thanks in advance for any help. Hello all, The exact thing that i need is to calculate how much days there is in between two dates. The only problem is that every thing that i found dont care about leap year Anyone have a function to do that? i have date of birth stored as DATE type in mysql. i tried this so it would show the age but it comes up blank. Code: [Select] $getprof = mysql_query("SELECT * FROM Profile WHERE username='$search'")or die(mysql_error()); while($rowprof = mysql_fetch_assoc($getprof)) { $username1 = $rowprof['username']; $location = $rowprof['location']; $gender = $rowprof['gender']; $dateofbirth = $rowprof['dateofbirth']; $information = $rowprof['information']; } function GetAge($dateofbirth) { // Explode the date into meaningful variables list($BirthYear,$BirthMonth,$BirthDay) = explode("-", $dateofbirth); // Find the differences $YearDiff = date("Y") - $BirthYear; $MonthDiff = date("m") - $BirthMonth; $DayDiff = date("d") - $BirthDay; // If the birthday has not occured this year if ($DayDiff < 0 || $MonthDiff < 0) $YearDiff--; return $YearDiff; } echo $YearDiff; I have an HTML table with the following columns: - Event - Price - # of Attendees - Total - Choose One The values are populated from a database, and I am using a loop to create the Table. The problem is that I have some syntax error where I am trying to calculate the Total Ticket Price?! Can someone help me figure what is wrong with my code? Code: [Select] <!-- Body --> <tbody> <?php // Fetch Comment record. $x=0; while (mysqli_stmt_fetch($stmt)){ //<!-- Row 1 --> echo ' <tr> <th scope="row" class="headerCol">'; echo $eventName . '<br />' . $eventLocation . '<br />' . $eventDate . ' </th> <td class="col2">' . $eventPrice . '<input type="hidden" name="eventCost[' . $x . ']" value="' . $eventPrice . '" /> </td> <td class="col3"> <select name="eventAttendees[' . $x . ']"> <option value="">--</option> <option value="1">1</option> <option value="2">2</option> <option value="3">3</option> <option value="4">4</option> </select> </td> <td class="col4">' . $eventCost*eventAttendees[$x] . '</td> <td class="col5"> <input name="eventChosen[' . $x . ']" type="submit" value="Buy Tickets" /> </td> </tr>'; } ?> </tbody> What I am trying to do/say on each row is "Take the Event Price and multiple it times the # of Attendees selected in the Row's Drop-Down field." Thanks, Debbie Hi I'm trying to figure out how to calculate how long since a datevariable I have stored is from whenever the page is loaded.. I currently have a stored datevariable in the format: YYYY-MM-DD H:m:s ... So basically what I wish to accomplish is figuring out whenever i load the page which has stored this variable, how much time has passed. I want it to show up as for example : '10 minutes ago'.. '1 hour 25minutes ago' if it's the same day.. if its more than 1 day old it's enough to show only the number of days.....'1week 3 days ago' etc etc |