PHP - Auto Calculate The Difference
Hello,
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 Similar TutorialsHey 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. 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 684425So a project I have simply to learn how it is done is to make an auto updating sitemap with a auto submitter. I have been doing a little research on sitemaps but haven't found much in the way of a tutorial or white paper or similar, anyway I was wondering if I am on the right track or not. What I was thinking for the auto-updating sitemap is since site maps are XML, when an article is published using my custom CMS/Blogging system, I make it rewrite the sitemap appending the new URL that will be generated. Then for the auto-submit, I can either make it a cron job or just manual press, but it would go though a for list of URLs, replacing the end part with my site map url. I think that is how it would be done. If you have a better idea, or can point out an article so I can understand a lot more with sitemaps, I will appreciate it, I am trying to learn as much as possible, I have gone to the offical website (sitemaps.org) but it doesn't have what I am looking for. Thanks, James //php code <?php include_once('con.php'); if(!empty($_GET['search'])) { $search = $connect->prepare('SELECT * FROM posts WHERE title LIKE :search'); $search->bindValue(':search', '%'.$_GET['search'].'%', PDO::PARAM_STR); $search->execute(); ?> <?php while($row = $search->fetch()) {?> <li class="result" onClick="searchValue('<?php echo $row['title'];?>')"><?php echo $row['title'];?></li> <?php } ?> <?php } ?> //ajax $('#inputsch').keyup(function(){ $.ajax({ type: 'GET', url: 'fetch.php', data:'search='+$(this).val(), success: function(data){ $('#box').show(); $('#box').html(data); } }); }); }); function searchValue(val) { $('#inputsch').val(val); $('#box').hide(); } //search box <form action="search.php"> <input id="inputsch" type="text" name="search" placeholder="search..." autocomplete="off" autofocus> <button type="submit" value="search" >search</button> </form> <div id="box"></div> //the problem here is when i click the result is only added to input, but i want it to autosubmit
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 I 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. 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? Actually what's the difference between Code: [Select] if(...) and Code: [Select] if(isset(...) 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? 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. 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> 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 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 Hello I am trying to get an action status based on e.g attackers_1 troops. Unfortunately I get nothing when I die the $strikeaction var here is my function and method I use to call it. Code: [Select] <?php function getStrikeAction($id){ $q = "SELECT * FROM `accountinfo_db` WHERE `id` = '$id'"; $res = mysql_query($q) or die(mysql_error()); $player = mysql_fetch_array($res); if($player['siegetech']>=1){ $strikeaction=($player['attackers_1'] * $player['siegetech'] * 120); $strikeaction+=($player['attackers_2'] * $player['siegetech'] * 1200); $strikeaction+=($player['attackers_3'] * $player['siegetech'] * 80); }else{ $strikeaction=($player['attackers_1'] * 120); $strikeaction+=($player['attackers_2'] * 1200); $strikeaction+=($player['attackers_3'] * 80); } $id = $player['id']; $q = "UPDATE `accountinfo_db` SET `strikeaction` = '$strikeaction' WHERE `id` = '$id'"; $res = mysql_query($q) or die(mysql_error()); return $stikeaction; } ?> Code: [Select] <?php echo getStrikeAction($player['id']);?> |