Calculating Against SQL Database, Returing Values
I was interested in trying to calculate against an SQL Table and return values that matched within the calculation. What i am trying to put together is a Zip Code Locator. I have a table "AREA" of Lat, Long and Zip Code numbers for the area im interested in. I also have a table "LOCATIONS" of Lat, Long and Zip code numbers for 25 different locations with data about Store Name, Address, etc.
What i would like to do is have a user input thier Zip code and that would launch one query, which would pull down the Lat & Long from the table "AREA". I would like to then Query the database "LOCATIONS" and calculate the distance between them using a formula. So it would do this.
User submit--->$_POST['zip'];---->Query and bring down LAT, LON from "AREA" table--->Query the LOCATIONS table, bring down all values---->calculate LAT, LON, from AREA table minus LAT, LON from the LOCATIONS table and populate to Variables the values that were LESS THAN 5 or something.
View Complete Forum Thread with Replies
See Related Forum Messages: Follow the Links Below to View Complete Thread
CALCULATING Row Values To Get A Total
My problem is,, that i have a PHP script that displays a table the table has the following colums firstname,surname,boots,hospital,woolworths,br,other, total the firstname and surname are grabbed from the database when the page loads, what i want is for the user to enter values in the boxes under the colums boots,woolworths,hospital etc then when they click submit,the page is refreshed, data submited into the database, bu them redisplayed in the table the values are calucated and each user is then given a total number of hours worked at those places. im really stuck guys, havent a clue how to go about this. so an example would be F S boots Hospital woolworths other total JOE BLOGS 0.8 0.8 0.8 0.8 HELP me 0.1 0.5 0.5 0.5 submit is pressed, data entered into the database, then page redisplayed with the total column totaled up. F S boots Hospital woolworths other total JOE BLOGS 0.8 0.8 0.8 0.8 3.2 HELP me 0.1 0.5 0.5 0.5 1.6
Calculating Some Formulas From Database Data
I am doing a project on beetle diversity and need to calculate a few diversity indices for a load of data i have collected. I thought that maybe i could make a program in php to do that for, and save a bit of time (as well as prevent calculation errors). I imagine this could be quite a bit of programming but i have dreamweaver to help me. Now what i have is a MySQL database full of data on beetle diversity with the following tables: Date - the date the sample is from Habitat - one of 9 habitats that i am testing between (ie. grass, stones, birch woodland, etc) Replica - ie 'Repeats', there were two replicas for each habitat from each date (A and B) Trap number - from each replica there were 6 traps Species - the species of beetle that was found in the trap (of course there are often more than one per trap) Number of Individuals - the number of individuals of that species found in that trap What i need to do is calculate Shannon-Weiner, Shannon Equitability and Margalefs Diversity indices for each replica from each date for each habitat (the data for the individual traps will be merged together). I have an idea of how to do it but what i am stumbling at is how to create a recordset which will calculate the total number of individuals for that species from that replica, date & habitat (I) and calculate the number of different species for that replica, date & habitat (S). Once i have S and I i should be able to write the formula in php to create the indices. Ideally this could be done in a way to allow for each repeating areas to be assigned so that all of the indices for that habitat (for each date and replica) could be shown on one page (to save a lot of clicking).
Calculating Dates From A Date In The Database?
I`m using this format of dates: $entry_date = strftime("%B %e, %Y %H:%M:%S", time()); And that time gets saved into the database (birth in ownedpets database): $res = mysql_query("SELECT id, owner, pet_type, pet_name, birth, food, play, datetime FROM ownedpets WHERE id=$id"); $rows = mysql_fetch_row($res); mysql_free_result($res); So let`s say in this case, the database birth value ($rows[4]) is October 19 2007 20:00:00. What do I do to tell php to check to see if the current date (hours and all don`t matter) is 21 days after the $rows[4]? Why I`m looking for this task: For the pets system, if the pet is 21 days after it`s birth, it will be an adult. But if it is not 21 days after it`s birth, it will still be a baby.
Returing The Array[x] Value
Searching through an array to find a specific string, which is fine and working. The code i am using is //$userToEdit is the user i want to edit //$userToEditLength is the string length of the name of the user i want to edit (i have also added '3' to the length to compensate for the <n>) foreach ($arrayText as $t) { if (substr($t, 0, $userToEditLength) == "<n>$userToEdit") { echo "String Matched!"; } } This all works fine. However, i would also like to output (now that i have found found the string exists) what array value the string resides in. I.e, does the $userToEdit string exist in $arrayText[2], or $arrayText[5] or $arrayText[4123]. Is there any way to do this in my substr if statement?
Retrieving Values From The Database
I am retrieving a value from the database and I insert the value as a value of a field The problem is that when the value has spaces then in the filed is viewed only the part of the value before the first space. If the value is not includes any spaces then the value appears in the field correct.
Displaying Values From A Database From An Include
I've got a URL going to a template, e.g. www.mydomain.com/product.php?id=product_a where the template is product.php the tag after the ? refers to the product that should be displyed in the template, in this case product_a Inside the template (product.php) I've got:- <? $url = $id.".htm"; include("$url"); ?> This works fine so far. How ever I've also got an include inside the the template (product_a.php), called product_info.php, which is another php file that displays the product version and the platforms that it sits on. so in the the include (product_info.php) I have:- <?php $db = mysql_connect("localhost", "username", "password"); mysql_select_db("DATABASE",$db); $result = mysql_query("SELECT version FROM table1 WHERE id = id",$db); do { if ($myrow[0] != "") { echo "$myrow[0]n"; } } while ($myrow = mysql_fetch_array($result));?> however this displays all the version numbers within the table (for every product) I just want it to display the version number of the value of $id (www.mydomain.com/product.php?id=product_a)
Unable To Insert All My Values Into The Database
I have an error in my code because its not inserting my $_session['identity'] into the database. I know the session has a value because I am able to display it on the page. it just wont insert it into the database. Code:
Droplists/database Values/sessions
I have many droplists that are populated with the values "open" and "closed". This one is called drop31. As with all of the droplists, which value is default is dependent on which value is currently stored in the db under "Lot31": Code:
Increasing Certain Values In MySQL Database
Each post in my announcement section has an IndexNo . . . so far I've had to do enter that automatically. How do I rig something up so that php will extract the most recent (or last entered) news post's IndexNo and increase it? The IndexNo is stored as an integer so increasing it is no worry . . . my real problem is how do I tell mySQL to give me the most recently posted news article?
Population Select Menu Using Php And Database Values
I have no idea how to go about this. so i would apreciate some help i want to populate the values in a html select menu from database values in one table so i want all the values from 1 particular field in the database to be displayed in the select menu as separate options.
Looping Database Values To Create An Array
I have a fairly simple php code problem I think, I want to loop values from a mysql database within an array to fill the array. I'v never done this before so your help would be valued if someone had the time. *denotes where I want to use database values*
Navigating Database Results And Posting New Values
I am trying to dynamically display results that I retrieve from my database i.e. only 5 results per page and code should automatically compute how many pages it needs and create links for each page. I have also added a link at the top of my page so that if user wants to POST new data he can post it. Problem is that when I click on page 2 or 3 or any numbered page and click on POST link it gives me following error "CGI Error The specified CGI application misbehaved by not returning a complete set of HTTP headers. The headers it did return are: And it did not tell about any header etc. Code:
Double Quoted Values From Database Won't Show Up In Form
I enter user input from a form into a mysql database using addslashes. When I access values with a double quote from the database they won't show up in a text form field as the default value. I use stripslashes when accessing database values, magic_quotes_gpc is on, magic_quotes_runtime is off, magic_quotes_sybase is off.
Calculating
how can I solve this: I have filled variable total (total oredr) This variable I must recalculate before sending, ie (look at HERE word) total = 100 Example --------------------- function process_button() { global $order; $process_button_string = web_draw_hidden_field('x_login', blah blah ....) . HERE web_draw_hidden_field('x_amount', number_format($order->info['total'], 2)) . Here must total be not 100, but divided with 5.85 How can I do that? I have tryed web_draw_hidden_field('x_amount', number_format($order->info['total/5.85'], 2)) . but did not work
Calculating Age
Im trying to pull a date of birth from my database (mysql) and use this to calculate a users age for display on the page. At the moment i'm storing the date of birth of each user in three different INT fields in my table: Year - INT - 4 Day - INT - 2 Month - INT - 2 here is the code im trying to use to calculate the age: Code:
Calculating
when calculating i am trying to add to variables together like this but it not work why. $total = ($a+$b);
Calculating
<?php $ok = "60"; if ($ok>30) || ($ok<=50){ print "30-50"; } else { print "60-over"; } ?> what is wrong ?
Calculating Colors
wondering if anyone has built or knows of a script out there that will calculate and output all of the websafe colors as hex values.
Calculating Duration
I'm trying to figure out how to calculate the duration when given 2 times. What I have is a script shown below in which you select a start time and end time from a drop down box, but would like some assistance on how to calculate the duration. An example: Start Time: 8:30 End Time: 9:30 Result: 1 Hour (60 mins) <tr> <td><b>Select Operation Start Time</b></td> <td><select name="start_time"> <option value="null">Select One</option> <? $start=mktime(8,30,0,date('m'),date('d'),date('Y')); for($i=$start;$i<=$start+32400;$i+=900) { $time=date("H:i",$i); echo "<option value=$time>$time</option>"; } ?> </select></td> </tr> <tr> <td><b>Select Operation End Time</b></td> <td><select name="end_time"> <option value="null">Select One</option> <? $start=mktime(8,30,0,date('m'),date('d'),date('Y')); for($i=$start;$i<=$start+32400;$i+=900) { $time=date("H:i",$i); echo "<option value=$time>$time</option>"; } ?> </select></td> </tr>
Calculating Tim - Easy For You! =)
I found out that i can calculate the dates e.g $today = strftime('%Y%m%d',mktime(0, 0, 0, date("m"), date("d"), date("Y"))); $yesterday = strftime('%Y%m%d',mktime(0, 0, 0, date("m"), date("d") - 1, date("Y"))); $dayBeforeYesterday = strftime('%Y%m%d',mktime(0, 0, 0, date("m"), date("d") - 2, date("Y"))); $dayBeforeTheDayBeforeYesterday = strftime('%Y%m%d',mktime(0, 0, 0, date("m"), date("d") - 2, date("Y"))); and so on........ This works even if we have the 1st of August $yesterday gives me the 31st july. Can I do this with times also? e.g. Iit it now 17:06 an i want to make minus 20 min (like abopve minus 1 day) and I want the result to be 16:46. I tried the above example, wit %H%M but it does not work?
Calculating Distance
Does anyone know of a service or script where you can enter two addresses and get a distance between, or do so by range? I know mapquest has something, but I'm looking for something a little less expensive and basic? If anyone has any ideas, that would be great. BTW, it must work with PHP and MySQL
Calculating Percentages?
<?php $value = '100'; $discount_value = '80'; // Value AFTER discount ?> What % do they save? How do I calculate this?
Calculating Free Space Available
Is there a way to tell how much space is remaining available for files? I'm working on a script that takes uploaded images and adds them to a database, but I'd like to check and make sure there's room for it first. I think there's probably going to be some type of issue with quotas, because that's how I found the problem. A user had uploaded a test version and got an error that a folder could not be created because of insufficient space remaining. And I know I could probably exec() out to df or something similar, but I would like it to work on Windows servers as well, so I'd prefer to keep it all in PHP code if possible.
Calculating CIDR Blocks
I have array of free IP addresses. One IP per line. Now I'm trying to share them to CIDR blocks /24 - /32. For example: if 1.1.1.0-1.1.1.255 is free, it returns array('.1.1.0/24') but let's say that 1.1.1.1 is used, then function should return array('.1.1.128/25', '.1.1.127/26', '.1.1.32/27', etc until free block doesn't fit). Here's my current code:
Calculating Future Dates
I have a variable ($today) that is simply $today = date("m/j/Y"); I want to get another variable for x months down the line, but using the php.net reference of the mktime and date command, my second date, as follows comes out in a large number. How can I make sure it is forwarding the date properly, and format it like mm/dd/yyyy? This is the line from php.net reference page. I need this to calculate properly, and format mm/dd/yyyy - just like my variable up top. $two_months_from_today = mktime(0,0,0,date("m")+2 ,date("d"),date("Y"));
Calculating Distance With Zipcodes
I have a DB of zipcdoes that includes it's lat. and long. and some other stuff. Is there an easy way of searching "within a 100 miles" etc of someone's location?
Calculating A Few Numbers Via A Form...
I am trying to put up a script where users enter certain info into a form and after they enter the info in, they click submit and the script makes a certain calculation using those numbers. For instance, the form should look something like this: Name: Age: Height in inches: Weight in pounds: Shoe size: Then the script takes the 4 numbers inputted in the age, height, weight, and shoe size rows and does this calculation and shows the user the result: (Height + Weight) * Age) / Shoe Size
Calculating Days Between Two Dates
I need to calculate the numbers of days (only the number of days) between two days, one a variable $row['user_cp_name'] in the format MM/DD/YY, and another, the current time. I've tried a bunch of tutorials on the internet and none seem to work properly.
Calculating Correct Time
Lets start off by giving you my code (Well the important sections of it!): <?php /**/# Total Time /**/$query = "SELECT sum(hours) FROM flights ".$condition; /**/$result=mysql_query($query); /**/$blcktime = number_format(mysql_result($result,0)); /**/$query = "SELECT sum(minutes) FROM flights ".$condition; /**/$result=mysql_query($query); /**/$blckmins = number_format(mysql_result($result,0)); echo "$blcktime:$blckmins"; ?> Okay this part works. Like if there is an entry that has 20 hours in hours table and 50 minutes in minute table it displays 20:50, but my problem is if there are more than one record (Which there will be) if the previous was still true and another record had 1:30 the total would be 21:80 but this of course is not correct addition of time. And this is not a 24 hour clock it simply displays the time someones been in a game so it can go lke 300:56 too. Now how would I get it so if the $minutes were greater than 60 and divisible by 60 it would add the correct numbers to the hours like $hours = $hours + $times_divisible; or something like that! I am okay with if..else..elseif statements but that would take forever to write. thats why I need a looping sttatement but I havent got a clue how to write it.
Calculating Random Numbers?
I have an average. Everybody knows that the formula to find an average number is: x = (a + b + c + d) / 4 x being the average. Say I already have an average, like this: 95 = (a + b + c + d) / 4 How would I generate four random numbers added together, divided by four, to get an average that equals 95?
Calculating Prices, Dollar Format?
I have some code which basically does some very simple addition and multiplication in order to get the total price. This is working fine, it's the way that it outputs it that troubles me. i.e 2.25 + 2.25 = $4.50 > but it just outputs it as $4.5 another example: 10 * 2 = $20.00 > but again it outputs it like $20 [ I need it to ouput like 20.00 but it does 20 instead. 6.5 instead of 6.50 etc. ] So say the total price is $total I was getting around it by just putting: $$total.00 but obviously with this it has to be a number like 10.00, 20.00 or 15.00 if it's 10.50 or 10.75 it doesn't work. In CF there is a 'dollar format' which can be used when outputting things like this. Is there a similar type function in PHP or an easy way around this?
Calculating Date Of Weekly Meeting
Just say I have a chat session on my site at the same time every week (eg - Friday 4pm EST). How can I calculate the time/date of the next meeting. Eg - if the current time is Thursday morning, it'll be the following day. If the current time is Friday afternoon, it needs to calculate the session in 7 days time (eg - that Friday's session has already ended). So is there a way I can calculate the date of the next session based on the current time/date? And how long till the next one? So my output would be "the next meeting is in 3 days, 22 hours and 12 minutes, on Friday 23 May 4pm"
Calculating Days From NOW From Future Datestamps
Hi All,I have datestamps of the format 11202006 (November 20th 2006) in the DB. All these datestamps are of the future. With reference to the datestamp, I need to query the database for all entries that are 90, 60, 29, 28, 27, 26, ... 02, 01 days away from NOW. So, if there are entries with datestamps 90 days from NOW, they will need to be displayed.The query will be run everyday through a CRON script. How do I create the queries? Would there be multiple SELECT queries? Eg: 90, 60, 29 .. 02, 01
Calculating Form Speed Process.
Each user have it's own technique with processing form (saving loading editing and so on). Let's think what we have 15 fields of different data. How much time you spend on scripting this form? To more concretely let's think what it's a hotel class!
Calculating The Selected Prices In A Listbox
I am wanting to know how I can add the all of the selected prices in a listbox? I need to add the selected prices altogether. The listbox should have only the names of the products. The listbox should be like below:
Calculating A Fictional Date, Not Working In PHP 4.4.4
I'm attempting to calculate the date for an online game that's set in the future. The games time is 4 times faster then our time so to figure it out I recorded the exact date/time in the game and the exact date/time in real time. Then all I need to do is multiply the seconds by 4 to the fictional date. Here is what I currently have: $realTime_start = mktime(17, 44, 20, 9, 25, 2007); $realTime_current = mktime(date("H"), date("i"), date("s"), date("n"), date("j"), date("Y")); $fomTime_start = mktime(14, 57, 0, 12, 8, 2007); $seconds = ($realTime_current - $realTime_start) * 4; $fom_date_full = date("H:i jS F Y",(strtotime("14:57 8 December 2007") + ($seconds))); $fom_year = substr($fom_date_full, (strlen($fom_date_full) - 4), strlen($fom_date_full)); $fom_year = 2404 + ($fom_year - 2007); $fom_date = date("H:i jS F",(strtotime("14:57 8 December") + ($seconds))); $fom_date_full = $fom_date." ".$fom_year; This works perfect in PHP 5+ but not on a server I'm using at the moment for testing (which uses PHP 4.4.4). I've referred to the manual to check the functions haven't changed from these versions and by the look there hasn't been any major changes. At the time of writing this the correct output is "22:18 17th January 2405" and the PHP 4 output is "02:17 10th February 2367".
Calculating An Equation Stored In A String
I am making a simple web-based interface that will allow users to add shapes into a DB. This will involve uploading a shape description, a jpeg of the shape and an equation for the area of the shape. It doesn't have to be too dynamic so i've kept the equation as a standard format, using x0 -> xn as the variables for the equation. For example, the equation for the area of a square would be x0 * x0 ( length * length ) as there is only one variable for deriving the area of a square. A rectangle would be x0 * x1 ( length * height ) etc. I then have code that reads the equation and counts how many variables, assigns names to these variables etc. This part is all fine. When the user selects a rectangle and enters 2 as variable1 and 3 as variable2, the code will retrieve x0*x1 as the rectangle's equation, replace the x0 with 2 and x1 with 3, using str_replace() function. This all works fine. So, I'm left with a string stored under a variable with value 2*3 The only problem is that i don't know how to calculate that string. I don't know how i would return a value of 6. Will it not always return the value as "2*3" because it is a string?!?
Calculating Span Between Earliest And Latest Dates
I'm wanting to find the span between the earliest and latest date in my database so I can calculate how many applications are filled out every day. It would be incredible if I could exclude weekends, but that's not necessary at this point. When I'm using a "date" type field in MySQL, I can use this ugly code:
Calculating Start And Ending Dates For A Week
Given a week number, how do you derive the starting date and ending date? I am trying to get the reverse of the yearweek function of MySQL. The yearweek function returns the year and week given a date. For example, yearweek(񟭂-08-01') returns 200231.
Math: Calculating Latitude And Longitude Between Two Points..
I have a bit of a problem with a pretty complicated mathematical expression. Basically, I'm trying to determine the initial heading between two points on the globe using latitude and longitude of the two points. I already know the distance between the two ($miles). Here's the expression: $Hdg=2*M_PI-acos((sin($lat2)-sin($lat1)*cos($miles))/(sin($miles)*cos($lat1))); When I echo $Hdg, I see: -1.#IND If the expression was working, I should see something like 134.9 for the following latitude/longitude combinations: $lat1 = 33.9780761 $lon1 = -83.9623772 $lat2 = 32.1950556 $lon2 = -81.8695556 $miles = 172.7381359 I can't find any references to what #IND means, so if anyone out there has any ideas, I'd be grateful.
Calculating Time Based Off Speed And Mileage
I am trying to complete a program for calculating time based off speed and distance traveled for creating motorcyle enduro route sheets. I am posting a test page I am working on. I know the formulas are probably wrong for getting the proper times and would appreciate any input. If you run this script the entries work most of the time. The problem is that at 24MPH the display "8 miles at 09:19:59" should have rounded to 9:20:00. This throws all following calculations off by 1 second. Code:
Adding New Values To An Array That Already Contains Values..
is it possible to append new values to an array that already has values in it?? say, i have my existing array; existing array; $array = array([66314] => 66314 , [66315] => 66315) ; then , when i check my checkbox on my next page, the ids should be appended to the $array: array that needs to be added to the $array; $array = array([66316] => 66316,[66317] => 66317,[66318] => 66318); how should it be done??
Assigning Values With Other Values
Say one has an array like such: array("lang=english", "nomusic=true", "name=Fred", "menu=false"); Is there a function in which I input the array and it makes all the things into variables with the other things as the content like: $lang="english"; $nomusic="true"; $name="fred"; $menu="false";
|