Jump to content

mac_gyver

Staff Alumni
  • Posts

    5,510
  • Joined

  • Days Won

    185

Everything posted by mac_gyver

  1. you are binding the month as though it is an integer. it is apparently the month abbreviation, a string. the internal conversion of those mismatched data types is probably causing all the month values to be matched. make sure you are treating data as the correct type.
  2. but does it produce the result you expect for different sets of data?
  3. test code that implements the suggestion i made - <?php $String = '48.010918880032534,-102.27871447619208,48.007298546092386,-102.27871873313035,48.007300404087175,-102.28410804755288,48.007302263082124,-102.28949736197535,48.007304121076913,-102.29488670439923,48.007305979071589,-102.30027601882199,48.010925506717513,-102.30027931864152,48.014545007363211,-102.30028259146059,48.018163867996407,-102.3002842242235,48.023143739025727,-102.30028731751861,48.023143709229146,-102.29967535036019,48.023140964347476,-102.29489150234963,48.023137856666608,-102.28949565918271,48.023137825974516,-102.28890660889158,48.023135053987971,-102.28409987201547,48.023131946306933,-102.2787040848512,48.018158490915084,-102.27870810340568,48.014539184972818,-102.27871024825487,48.010918880032534,-102.27871447619208'; $Exp = explode(',',$String); if(is_array($Exp)){ $C = 1; foreach($Exp as $Exp2){ if(!empty($Exp2)){ if($Exp2 > 0){ $latitude[] = $Exp2; } else { $longitude[] = $Exp2; } } } } $m['maxlat'] = max($latitude); $m['minlat'] = min($latitude); $m['maxlong'] = max($longitude); $m['minlong'] = min($longitude); // the prefect corners $c[1] = array($m['minlat'],$m['minlong']); $c[2] = array($m['maxlat'],$m['maxlong']); $c[3] = array($m['minlat'],$m['maxlong']); $c[4] = array($m['maxlat'],$m['minlong']); function distance($lat1, $lon1, $lat2, $lon2, $unit) { $theta = $lon1 - $lon2; $dist = sin(deg2rad($lat1)) * sin(deg2rad($lat2)) + cos(deg2rad($lat1)) * cos(deg2rad($lat2)) * cos(deg2rad($theta)); $dist = acos($dist); $dist = rad2deg($dist); $miles = $dist * 60 * 1.1515; $unit = strtoupper($unit); if ($unit == "K") { return ($miles * 1.609344); } else if ($unit == "N") { return ($miles * 0.8684); } else { return $miles; } } foreach($c as $corner=>$arr){ foreach($latitude as $key=>$lat){ $dist = abs(distance($arr[0],$arr[1],$lat,$longitude[$key], "M")); $result[$corner]["$dist"][] = array($lat,$longitude[$key]); } ksort($result[$corner]); } echo "The four corners found are:<br>"; foreach($result as $arr){ $first = array_shift($arr); echo $first[0][0] .' '. $first[0][1] . '<br>'; }
  4. exactly what i was going to write. without a state-able rule, there's no way to write any code to do it. how does this sound - form the prefect rectangle using the min/max x/y values then find the distance between those 4 "prefect" corners and the actual points and the closest point to each of the "perfect" corner points is the corner point you are trying to find?
  5. it's probably for consistency purposes. you can use the same line of code to fetch the next element from the array no matter how rows are in the array being operated on.
  6. it might help if you state what it is you are trying to accomplish, rather than stating what you are doing that doesn't produce the result you want. what i think you are trying to do is use a search radius and add/subtract that radius to the starting point's lat/longitude to quick find all the points within that bounding square, then to actually calculate the distance from the starting point to those quick find points to remove any that are outside the search radius.
  7. an issue that stands out is that you are using number_format() on values, not just for display purposes, but that those formatted numbers are being used in the calculations. when you end up with a number with a comma 1000's separator in it, only the leading number before the comma will be used in the calculations. you should only use number_format() right before you display a value and only to produce the displayed output. the original variable needs to contain the unformatted value.
  8. for drop-down select menus output selected="selected" inside the <option > tag you want to be selected.
  9. as a continuation of the above reply, the link i posted is the same information as the link awjudd posted in his last reply. using this method will shorted your code from about 13 lines to 3 lines. your original code needed to do what pbs posted, but in order to use $stmt->num_rows you need to store the result using $stmt->store_result() first. the $stmt->get_result() in the code posted by awjudd returns a mysqli_result that you need to fetch the row from before you can access the count value.
  10. there's a query that does that - http://dev.mysql.com/doc/refman/5.5/en/insert-on-duplicate.html
  11. a form page like that linked to script is using would be simple to create. 1) read the first two lines of the uploaded csv file. extract the header names from the first line and extract sample data from the second line. 2) read the database table definition to get the column names and produce the drop-down menus. 3) when the form is submitted, any drop-downs that have been picked will define which csv column name goes with a database column name. any drop-downs that have not been picked don't map to anything and would cause that csv column to be ignored in the data. the submitted information (or sets of data you have saved somewhere) would produce a map like this - // list of csv header names to database column names $field_list['Latitude'] = 'latitude'; $field_list['Longitude'] = 'longitude'; $field_list['DateOccurred'] = 'date'; $field_list['Tripname'] = 'trip'; $field_list['Angle'] = 'angle'; $field_list['Speed'] = 'speed'; $field_list['Altitude'] = 'alt'; the $want array in the code i posted above would be produced from the $field_list array keys. the $fields variable in the code i posted would need to loop through the resulting $map array to get the csv fields in the same order as the data will be and get the actual database column names out of the above $field_list array.
  12. everything i posted had to do with working with an arbitrary order of the fields in the csv file, not relating a specific csv header name to its corresponding database column name. do you want to do this upon each import or do you just want to set up a static definition that relates the csv header names, like "DateOccurred" to a database column name, like "date"? to do the former, you would need a script like the one you linked to. to do the latter, you could use the code I posted and just add one array that lists the database table columns and build the field list in the query from that array.
  13. sticking with a problem until it is solved is actually a highly valued trait, no matter what the subject is. if you just post your code and your error on any help forum and expect a copy/paste solution that won't involve any effort on your part, you are in for a huge surprise.
  14. only data values can be put into a prepared query after it is prepared. a keyword like "ASC" is not data. it's part of the query syntax and can only be put into the query at the time it is passed to the ->prepared() method.
  15. the order doesn't matter (see the code i posted.) the field list in the query and the data in the query match each other. if any of the fields you do want are not present in the actual data file, you would need to set up appropriate default values in your database table since the code won't include a column name that isn't in the header line.
  16. as a continuation of the above reply, once you have the result from array_intersect, you can use array_intersect_key against the $data array to get just the correct data values from it. quicker to just post some code - // the fields you want (these can be in any order) $want = array('Latitude','Longitude','DateOccurred','Tripname','Angle','Speed','Altitude'); // the fields from the header line (code to get this from your data is left up to you) $have = array('Latitude','Longitude','DateOccurred','field3','field4','field5','Tripname','field7','Angle', 'field9','field10','field11','field12','field13','field14','Speed','Altitude','field17'); $map = array_intersect($have,$want); // get only the fields you want $fields = implode(',',$map); // use this to make the list of field names in the query statement $date_field = array_search('DateOccurred', $map); // find the position of the date field for special handling // make up some test data. the order of fields matches the $have array (your code would get this from the file) $data = array('Latitude1','Longitude1','11/4/2013','field31','field41','field51','Tripname1','field71', 'Angle1','field91','field101','field111','field121','field131','field141','Speed1','Altitude1', 'field171'); // processing of the data starts here ---------------------------------------- $data = array_intersect_key($data,$map); // get only the data fields you want $data[$date_field] = date('Y-m-d H:i:s',strtotime(str_replace('/', '-', $data[$date_field]))); // format the date $data = array_map('mysql_real_escape_string',$data); // treating all fields like strings and apply escape $sql = "INSERT INTO temp ($fields) VALUES ('".implode("','",$data)."')"; // treating all fields like strings echo $sql;
  17. you would need to temporarily comment out the header() statements.
  18. you would get the field names from the header line into an array and have an array of the fields you want. use array_intersect to filter out all the field names that you don't want between the first array and the second. the keys in the resulting array will be the index offsets [0],[16],[6], ... in the $data array for the corresponding field name. if you post an example of the format of the header line someone could post code showing how to do this.
  19. web pages contain html tags. the html tag for an image is <img src='a url'> in this case, the url would be that of your pchart php script.
  20. each of your header() redirect statements need an exit statement after it to prevent the rest of the code on the page from running. you also cannot echo or output any characters to the browser before a header() statement. if you are actually seeing the echoed output, the header() statement won't work at all and if you are not seeing the output and the header() is working it means that php is buffering output and echoing things to help you debug won't work.
  21. you need to actually debug why your code is not returning the expected result. by just randomly trying different code, you are never going to find out why it is failing and the reason it is failing might be somewhere besides the code you are changing. the first step would be to form the query statement in a php variable and then echo that variable so that you know what the actual query statement is.
  22. you need to post just the relevant part of the code that you need help with, the preg_match statement and possibly a few lines leading up to it if you are forming the match pattern in a variable.
  23. when you successfully prepare a query, it returns an instance of the mysqli_stmt class. bind_param is a method of the mysqli_stmt class, not a method of the mysqli class. there are excellent examples in the php.net mysqli documentation.
  24. you need to find out how the site was hacked, where the security hole is, before you would have anything to fix.
  25. posting both your form and your php form processing code would allow someone to see what your code is doing and what to change in it.
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.