Jump to content

hitman6003

Members
  • Posts

    1,807
  • Joined

  • Last visited

Everything posted by hitman6003

  1. Check to see if your locale is set correctly. If it is, ensure that the server has the correct time set (for the time zone it is located in, not yours). Also ensure that the server is aware of what time zone it is in. http://www.php.net/setlocale
  2. Use any of the classes found here: http://www.google.com/search?hl=en&q=php+Captcha&btnG=Google+Search or here: http://www.google.com/custom?domains=www.phpclasses.org&q=captcha&sa=Search&sitesearch=www.phpclasses.org&client=pub-2951707118576741&forid=1&channel=5742870948&ie=ISO-8859-1&oe=ISO-8859-1&cof=GALT%3A%23663399%3BGL%3A1%3BDIV%3A%23222222%3BVLC%3A663399%3BAH%3Acenter%3BBGC%3AA3C5CC%3BLBGC%3AA3C5CC%3BALC%3A0000FF%3BLC%3A0000FF%3BT%3A000000%3BGFNT%3A0000FF%3BGIMP%3A0000FF%3BLH%3A50%3BLW%3A256%3BL%3Ahttp%3A%2F%2Ffiles.phpclasses.org%2Fgraphics%2Fgooglesearch.jpg%3BS%3Ahttp%3A%2F%2Fwww.phpclasses.org%2Fsearch.html%3BFORID%3A1%3B&hl=en
  3. change: $result=mysql_query($query); to $result=mysql_query($query) or die(mysql_error()); And see what the error is.
  4. I had to tweak the query some, but this works... function distance($lat_of_zip_selected, $long_of_zip_selected, $unit = 'M') { global $database_conn; $lat = $lat_of_zip_selected; $lon = $long_of_zip_selected; $query = "SELECT zip, state, (DEGREES(ACOS((SIN(RADIANS(`lat`)) * SIN(RADIANS($lat))) + COS(RADIANS(`lat`)) * COS(RADIANS($lat)) * COS(RADIANS( `long` - $lon )))) * 60 * 1.1515) AS distance_miles " . "FROM zip_codes ORDER BY distance_miles ASC LIMIT 10"; $result = mysql_query($query) or die(mysql_error()); while ($row = mysql_fetch_assoc($result)) { $miles = $row['distance_miles']; switch (strtoupper($unit)) { case 'K': $ret = $miles * 1.609344; break; case 'N': $ret = $miles * 0.8684; break; default: $ret = $miles; } $data[$row['zip']] = $miles; } return $data; } Took me 30 minutes to realize that the last operation conducted was rad2deg, rather than deg2rad...which was throwing off the DEGREES and RADIANS calls in the SQL...oops
  5. I think this will work....I haven't tested it because I don't have a database that contains zips along with lat and long...if you can tell me where to get one, I'd be willing to play with it...I've never played with this stuff before so it's entertaining. Anyway, it returns an array of the 10 closest zips and their distance... //lat and long passed to func are the ones selected by the user function distance($lat_of_zip_selected, $long_of_zip_selected, $unit = 'M') { $sin_la = sin(deg2rad($lat_of_zip_selected)); $cos_la = cos(deg2rad($lat_of_zip_selected)); //lat = the latitue column in your table //long = the longitude column in your table //zip = the zip code column in your table //zip_locations = the name of your table $query = "SELECT zip, (ACOS(RADIANS(( SIN(RADIANS(lat)) * $sin_la + COS(RADIANS(lat)) * $cos_la * COS(RADIANS( ($long_of_zip_selected - long) )) ))) * 60 * 1.1515) AS distance_miles " . "FROM zip_locations ORDER BY distance_miles DESC LIMIT 10"; $result = mysql_query($query) or die(mysql_error()); while ($row = mysql_fetch_assoc($result)) { $miles = $row['distance_miles']; switch (strtoupper($unit)) { case 'K': $ret = $miles * 1.609344; break; case 'N': $ret = $miles * 0.8684; break; default: $ret = $miles; } $data[$row['zip']] = $miles; } return $data; }
  6. There doesn't appear to be anything so wrong that it would cause your code to fail outright. The most likely culprit is that you have a syntax error elsewhere in your code and display errors is set to 0 in your php.ini file, so it will not show syntax errors. It is always a good idea to use single quotes when addressing array elements: $fav = '<a href=' . str_replace(" ", "+", $_POST['url']) . '>' . $_POST['mysearch'] . '</a>';
  7. Look at this page of the tutorial: http://www.phpfreaks.com/tutorials/129/2.php specifically the part about creating the full text index............
  8. I swear I looked in the manual for that exact sentence and didn't see it....I must be going crazy
  9. Sometimes using isset($_POST['submit']) can be dangerous. Some browsers (I'm not sure which off hand) will not send the submit variable if the submit button is not pressed. This means if the user simply types in the form, then presses the "Enter" key, the submit button's value is not sent, which means that the $_POST array key "submit" will not exist.
  10. You need to escape the backslash in your regular expression syntax.... ^[A-Za-z0-9\\n]*$
  11. After reading through the manual, it looks like having a decimal point ( . ) in your number will cause it to be read as a numeric string, rather than an integer...from the man page on integers: http://us3.php.net/manual/en/language.types.integer.php EDIT: here is an example of how php does it's type comparisons: $int = 10; $float = 10.55; $string = "10.90"; $not_a_number = "abcd"; echo "<pre> int $int: is_int: " . is_int($int) . " is_float: " . is_float($int) . " is_string: " . is_string($int) . " is_numeric: " . is_numeric($int) . " float $float: is_int: " . is_int($float) . " is_float: " . is_float($float) . " is_string: " . is_string($float) . " is_numeric: " . is_numeric($float) . " string $string: is_int: " . is_int($string) . " is_float: " . is_float($string) . " is_string: " . is_string($string) . " is_numeric: " . is_numeric($string) . " not_a_number $not_a_number: is_int: " . is_int($not_a_number) . " is_float: " . is_float($not_a_number) . " is_string: " . is_string($not_a_number) . " is_numeric: " . is_numeric($not_a_number);
  12. If you are pulling the value from the database, then you have presumably checked the value previously to insure that it is an integer. If so, just typecast it to an int before passing to your function. You may also want to consider using the is_numeric function instead of is_int.... http://www.php.net/is_numeric
  13. http://www.phpfreaks.com/tutorials/129/0.php
  14. It doesn't matter in the end if it is returned as a string or int...php will convert it to the type that it needs to.
  15. I took the example provided here: http://www.vias.org/tmdatanaleng/cc_quartile.html You could easily turn this into a function.... $values = array(-20, -4, -1, -1, 0, 1, 2, 3, 4, 4, 7, 7, 8, 11, 11, 12, 12, 15, 18, 22); $count = count($values); $first = round( .25 * ( $count + 1 ) ) - 1; $second = ($count % 2 == 0) ? ($values[($count / 2) - 1] + $values[$count / 2]) / 2 : $second = $values[($count + 1) / 2]; $third = round( .75 * ( $count + 1 ) ) - 1; echo "<pre>" . print_r($values, true) . " first = $first<br /> values[first] = $values[$first]<br /> <br /> second = $second<br /> <br /> third = $third<br /> values[third] = $values[$third]";
  16. Do you have the form encoding set correctly for your html form? http://us2.php.net/manual/en/features.file-upload.php
  17. Use javascript. If you use php you will have to have the user refresh the page (or the page auto refresh)...and refreshing every 1 second will confuse the user. Unless you are using CLI php.......
  18. Or, if you want to functionalize it: function find_day_of_prev_week($year, $month, $day, $day_of_week) { /* $year, $month, and $day should be integers, obviously valid date ranges. $day_of_week should be an int from 0 to 6: 0 = Sunday, 6 = Saturday */ $day_of_this_week = date("w", mktime(null, null, null, $month, $day, $year)); //determine if there is an offset, and if so, what it is //this will not modify the date if today is the day we are looking for... //i.e. if we are looking for wednesday, and today is wednesday, it will return today. //that behavior can be changed by commenting the below and uncommenting it's successor $offset = ($day_of_this_week != $day_of_week) ? ($day_of_this_week - $day_of_week) + 7 : 0; //$offset = $day_of_this_week - $day_of_week + 7; //take note that this will return less than zero if the previous day is in a previous month... //it is intended to be passed to the mktime function return $day - $offset; } echo ' Today: ' . date("D M j G:i:s T Y") . '<br /> Last Today: ' . find_day_of_prev_week(date('Y'), date('m'), date('d'), date('w')) . '<br />'; $day_of_week_of_first = date('w', mktime(0, 0, 0, date("m"), 1, date("Y"))); $prev_day = find_day_of_prev_week(date('Y'), date('m'), 1, $day_of_week_of_first); $same_day_as_week_prev = date("D M j G:i:s T Y", mktime(0, 0, 0, date('m'), $prev_day, date('Y'))); echo' <br />The First: ' . date("D M j G:i:s T Y", mktime(0, 0, 0, date("m"), 1, date("Y"))) . '<br /> The previous d-o-w: ' . $prev_day . '<br /> Passed to mktime and date: ' . $same_day_as_week_prev;
  19. Arrays can contain mixed variable types. You may want to read this page for further information: http://us3.php.net/manual/en/language.types.array.php
  20. Once you get above a few tens of files this process will get very very slow and cumbersome. You may want to look into a CMS or some other method that will store your data in a database that can be easily searched. You may even consider a cron job that will parse your files and insert them into a database that has a fulltext index set up for the field.
  21. Change: $result = mysql_query("select * from featured"); to $result = mysql_query("select * from featured") or die(mysql_error());
  22. <?php //get variables for today's date list($year, $month, $day, $day_of_week) = explode("-", date("Y-m-d-w")); //determine if there is an offset, and if so, what it is //using the date('w') function the days are 0-6, so we can //change which day we want by changing the 3's below: //-------------------------\/--------------------\/------- $offset = ($day_of_week != 3) ? ($day_of_week - 3) + 7 : 0; //use the offset to get the datestring for last Wednesday echo "filename: shipping_" . date("mdy", mktime(null, null, null, $month, $day - $offset, $year)); ?>
  23. What do you mean by "non HTML elements pages"? You can use the dir class to open a directory, the read through the files, select the ones you want, then use file_get_contents to read the file and use strpos and the regex functions to search for your string. http://www.php.net/dir http://www.php.net/file_get_contents http://www.php.net/strpos
  24. The type doesn't really matter in PHP since it's dynamically typed. You can force it to typecast if you like, but there's no reason to since PHP will convert from string to int, and vice-versa, when necessary. Reference Type Juggling in the php manual...here's an english link: http://us2.php.net/manual/en/language.types.type-juggling.php
×
×
  • 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.