Jump to content

jakebur01

Members
  • Posts

    885
  • Joined

  • Last visited

Everything posted by jakebur01

  1. I've been trying to figure this out. Could someone please give me some direction with what I am trying to do?
  2. Ok, I have tryed different things with this and nothing i've come up with has worked. What I have is a PHP Class and MySQL table to find the distance between zip codes and * find all zip codes within a given mileage or kilometer range. I have a table named zip_code with all 40000 zip codes in it. The program works great when calculating a distance between two zips, and returning zips within a given range. What I am trying to do is add onto the code to have it select from a table I have created called "smithssc" the dealers within range. I have 5 colums in the table: Dealer, Address, City, State, and Zip. I was trying to add something like this onto it. I am not connecting my dots right. $result = mysql_query("SELECT * FROM smithssc WHERE Zip = '$key'", $db); echo "<table>"; while($myrow = mysql_fetch_array ($result)) { echo"<tr><td>"; echo$myrow["Dealer"]; echo"<td>"; echo$myrow["Address"]; echo"<td>"; echo$myrow["City"]; echo"<td>"; echo$myrow["State"]; echo"<td>"; echo$myrow["Zip"]; } echo "</table>"; Using this will not pull anything up with that variable $key. Here is the code: demo.php <!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>Zip Code Range and Distance Calculation Demo</title> <style type="text/css" lang="en"> BODY, P { font-family: sans-serif; font-size: 9pt; } H3 { font-family: sans-serif; font-size: 14pt; } </style> </head> <body> <?php /* DEMO for using the zipcode PHP class. By: Micah Carrick Questions? Comments? Suggestions? email@micahcarrick.com */ require_once('zipcode.class.php'); // zip code class // Open up a connection to the database. The sql required to create the MySQL // tables and populate them with the data is in the /sql subfolder. You can // upload those sql files using phpMyAdmin or a MySQL prompt. You will have to // modify the below information to your database information. $db = mysql_connect('localhost','myuser','mypass') or die(mysql_error()); mysql_select_db('mydata') or die(mysql_error()); // Below is an example of how to calculate the distance between two zip codes. echo '<h3>A sample calculating the distance between 2 zip codes: 93001 and 60618</h3>'; $z = new zipcode_class; $miles = $z->get_distance(97214, 98501); if ($miles === false) echo 'Error: '.$z->last_error; else echo "Zip code <b>97214</b> is <b>$miles</b> miles away from <b>98501</b>.<br />"; // Below is an example of how to return an array with all the zip codes withing // a range of a given zip code along with how far away they are. The array's // keys are assigned to the zip code and their value is the distance from the // given zip code. echo '<h3>A sample getting all the zip codes withing a range: 90 miles from 97214</h3>'; $zips = $z->get_zips_in_range('97214', 90, _ZIPS_SORT_BY_DISTANCE_ASC, true); if ($zips === false) echo 'Error: '.$z->last_error; else { foreach ($zips as $key => $value) { echo "Zip code <b>$key</b> is <b>$value</b> miles away from <b>97214</b>.<br />"; } // One thing you may want to do with this is create SQL from it. For example, // iterate through the array to create SQL that is something like: // WHERE zip_code IN ('93001 93002 93004') // and then use that condition in your query to find all pizza joints or // whatever you're using it for. Make sense? Hope so. echo "<br /><i>get_zips_in_range() executed in <b>".$z->last_time."</b> seconds.</i><br />"; } // And one more example of using the class to simply get the information about // a zip code. You can then do whatever you want with it. The array returned // from the function has the database field names as the keys. I just do a // couple string converstions to make them more readable. echo '<h3>A sample getting details about a zip code: 97214</h3>'; $details = $z->get_zip_details('97214'); if ($details === false) echo 'Error: '.$z->last_error; else { foreach ($details as $key => $value) { $key = str_replace('_',' ',$key); $key = ucwords($key); echo "$key: $value<br />"; } } ?> </body> </html> zipcode.class.php <?php /******************************************************************************* * ZIP Code and Distance Claculation Class ******************************************************************************* * Author: Micah Carrick * Email: email@micahcarrick.com * Website: http://www.micahcarrick.com * * File: zipcode.class.php * Version: 1.2.0 * Copyright: (c) 2005 - Micah Carrick * You are free to use, distribute, and modify this software * under the terms of the GNU General Public License. See the * included license.txt file. * ******************************************************************************* * VERION HISTORY: * v1.2.0 [Oct 22, 2006] - Using a completely new database based on user contributions which resolves many data bugs. - Added sorting to get_zips_in_range() - Added ability to include/exclude the base zip from get_zips_in_range() * v1.1.0 [Apr 30, 2005] - Added Jeff Bearer's code to make it MUCH faster! * v1.0.1 [Apr 22, 2005] - Fixed a typo * v1.0.0 [Apr 12, 2005] - Initial Version * ******************************************************************************* * DESCRIPTION: * A PHP Class and MySQL table to find the distance between zip codes and * find all zip codes within a given mileage or kilometer range. * ******************************************************************************* */ // constants for setting the $units data member define('_UNIT_MILES', 'm'); define('_UNIT_KILOMETERS', 'k'); // constants for passing $sort to get_zips_in_range() define('_ZIPS_SORT_BY_DISTANCE_ASC', 1); define('_ZIPS_SORT_BY_DISTANCE_DESC', 2); define('_ZIPS_SORT_BY_ZIP_ASC', 3); define('_ZIPS_SORT_BY_ZIP_DESC', 4); // constant for miles to kilometers conversion define('_M2KM_FACTOR', 1.609344); class zipcode_class { var $last_error = ""; // last error message set by this class var $last_time = 0; // last function execution time (debug info) var $units = _UNIT_MILES; // miles or kilometers var $decimals = 2; // decimal places for returned distance function get_distance($zip1, $zip2) { // returns the distance between to zip codes. If there is an error, the // function will return false and set the $last_error variable. $this->chronometer(); // start the clock if ($zip1 == $zip2) return 0; // same zip code means 0 miles between. // get details from database about each zip and exit if there is an error $details1 = $this->get_zip_point($zip1); $details2 = $this->get_zip_point($zip2); if ($details1 == false) { $this->last_error = "No details found for zip code: $zip1"; return false; } if ($details2 == false) { $this->last_error = "No details found for zip code: $zip2"; return false; } // calculate the distance between the two points based on the lattitude // and longitude pulled out of the database. $miles = $this->calculate_mileage($details1[0], $details2[0], $details1[1], $details2[1]); $this->last_time = $this->chronometer(); if ($this->units == _UNIT_KILOMETERS) return round($miles * _M2KM_FACTOR, $this->decimals); else return round($miles, $this->decimals); // must be miles } function get_zip_details($zip) { // This function pulls the details from the database for a // given zip code. $sql = "SELECT lat AS lattitude, lon AS longitude, city, county, state_prefix, state_name, area_code, time_zone FROM zip_code WHERE zip_code='$zip'"; $r = mysql_query($sql); if (!$r) { $this->last_error = mysql_error(); return false; } else { $row = mysql_fetch_array($r, MYSQL_ASSOC); mysql_free_result($r); return $row; } } function get_zip_point($zip) { // This function pulls just the lattitude and longitude from the // database for a given zip code. $sql = "SELECT lat, lon from zip_code WHERE zip_code='$zip'"; $r = mysql_query($sql); if (!$r) { $this->last_error = mysql_error(); return false; } else { $row = mysql_fetch_array($r); mysql_free_result($r); return $row; } } function calculate_mileage($lat1, $lat2, $lon1, $lon2) { // used internally, this function actually performs that calculation to // determine the mileage between 2 points defined by lattitude and // longitude coordinates. This calculation is based on the code found // at http://www.cryptnet.net/fsp/zipdy/ // Convert lattitude/longitude (degrees) to radians for calculations $lat1 = deg2rad($lat1); $lon1 = deg2rad($lon1); $lat2 = deg2rad($lat2); $lon2 = deg2rad($lon2); // Find the deltas $delta_lat = $lat2 - $lat1; $delta_lon = $lon2 - $lon1; // Find the Great Circle distance $temp = pow(sin($delta_lat/2.0),2) + cos($lat1) * cos($lat2) * pow(sin($delta_lon/2.0),2); $distance = 3956 * 2 * atan2(sqrt($temp),sqrt(1-$temp)); return $distance; } function get_zips_in_range($zip, $range, $sort=1, $include_base) { // returns an array of the zip codes within $range of $zip. Returns // an array with keys as zip codes and values as the distance from // the zipcode defined in $zip. $this->chronometer(); // start the clock $details = $this->get_zip_point($zip); // base zip details if ($details == false) return false; // This portion of the routine calculates the minimum and maximum lat and // long within a given range. This portion of the code was written // by Jeff Bearer (http://www.jeffbearer.com). This significanly decreases // the time it takes to execute a query. My demo took 3.2 seconds in // v1.0.0 and now executes in 0.4 seconds! Greate job Jeff! // Find Max - Min Lat / Long for Radius and zero point and query // only zips in that range. $lat_range = $range/69.172; $lon_range = abs($range/(cos($details[0]) * 69.172)); $min_lat = number_format($details[0] - $lat_range, "4", ".", ""); $max_lat = number_format($details[0] + $lat_range, "4", ".", ""); $min_lon = number_format($details[1] - $lon_range, "4", ".", ""); $max_lon = number_format($details[1] + $lon_range, "4", ".", ""); $return = array(); // declared here for scope $sql = "SELECT zip_code, lat, lon FROM zip_code "; if (!$include_base) $sql .= "WHERE zip_code <> '$zip' AND "; else $sql .= "WHERE "; $sql .= "lat BETWEEN '$min_lat' AND '$max_lat' AND lon BETWEEN '$min_lon' AND '$max_lon'"; $r = mysql_query($sql); if (!$r) { // sql error $this->last_error = mysql_error(); return false; } else { while ($row = mysql_fetch_row($r)) { // loop through all 40 some thousand zip codes and determine whether // or not it's within the specified range. $dist = $this->calculate_mileage($details[0],$row[1],$details[1],$row[2]); if ($this->units == _UNIT_KILOMETERS) $dist = $dist * _M2KM_FACTOR; if ($dist <= $range) { $return[str_pad($row[0], 5, "0", STR_PAD_LEFT)] = round($dist, $this->decimals); } } mysql_free_result($r); } // sort array switch($sort) { case _ZIPS_SORT_BY_DISTANCE_ASC: asort($return); break; case _ZIPS_SORT_BY_DISTANCE_DESC: arsort($return); break; case _ZIPS_SORT_BY_ZIP_ASC: ksort($return); break; case _ZIPS_SORT_BY_ZIP_DESC: krsort($return); break; } $this->last_time = $this->chronometer(); if (empty($return)) return false; return $return; } function chronometer() { // chronometer function taken from the php manual. This is used primarily // for debugging and anlyzing the functions while developing this class. $now = microtime(TRUE); // float, in _seconds_ $now = $now + time(); $malt = 1; $round = 7; if ($this->last_time > 0) { /* Stop the chronometer : return the amount of time since it was started, in ms with a precision of 3 decimal places, and reset the start time. We could factor the multiplication by 1000 (which converts seconds into milliseconds) to save memory, but considering that floats can reach e+308 but only carry 14 decimals, this is certainly more precise */ $retElapsed = round($now * $malt - $this->last_time * $malt, $round); $this->last_time = $now; return $retElapsed; } else { // Start the chronometer : save the starting time $this->last_time = $now; return 0; } } }
  3. Ok, I have tryed different things with this and nothing i've come up with has worked. What I have is a PHP Class and MySQL table to find the distance between zip codes and * find all zip codes within a given mileage or kilometer range. I have a table named zip_code with all 40000 zip codes in it. The program works great when calculating a distance between two zips, and returning zips within a given range. What I am trying to do is add onto the code to have it select from a table I have created called "smithssc" the dealers within range. I have 5 colums in the table: Dealer, Address, City, State, and Zip. I was trying to add something like this onto it. I am not connecting my dots right. $result = mysql_query("SELECT * FROM smithssc WHERE Zip = '$key'", $db); echo "<table>"; while($myrow = mysql_fetch_array ($result)) { echo"<tr><td>"; echo$myrow["Dealer"]; echo"<td>"; echo$myrow["Address"]; echo"<td>"; echo$myrow["City"]; echo"<td>"; echo$myrow["State"]; echo"<td>"; echo$myrow["Zip"]; } echo "</table>"; Using this will not pull anything up with that variable $key. Here is the code: demo.php <!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>Zip Code Range and Distance Calculation Demo</title> <style type="text/css" lang="en"> BODY, P { font-family: sans-serif; font-size: 9pt; } H3 { font-family: sans-serif; font-size: 14pt; } </style> </head> <body> <?php /* DEMO for using the zipcode PHP class. By: Micah Carrick Questions? Comments? Suggestions? email@micahcarrick.com */ require_once('zipcode.class.php'); // zip code class // Open up a connection to the database. The sql required to create the MySQL // tables and populate them with the data is in the /sql subfolder. You can // upload those sql files using phpMyAdmin or a MySQL prompt. You will have to // modify the below information to your database information. $db = mysql_connect('localhost','myuser','mypass') or die(mysql_error()); mysql_select_db('mydata') or die(mysql_error()); // Below is an example of how to calculate the distance between two zip codes. echo '<h3>A sample calculating the distance between 2 zip codes: 93001 and 60618</h3>'; $z = new zipcode_class; $miles = $z->get_distance(97214, 98501); if ($miles === false) echo 'Error: '.$z->last_error; else echo "Zip code <b>97214</b> is <b>$miles</b> miles away from <b>98501</b>.<br />"; // Below is an example of how to return an array with all the zip codes withing // a range of a given zip code along with how far away they are. The array's // keys are assigned to the zip code and their value is the distance from the // given zip code. echo '<h3>A sample getting all the zip codes withing a range: 90 miles from 97214</h3>'; $zips = $z->get_zips_in_range('97214', 90, _ZIPS_SORT_BY_DISTANCE_ASC, true); if ($zips === false) echo 'Error: '.$z->last_error; else { foreach ($zips as $key => $value) { echo "Zip code <b>$key</b> is <b>$value</b> miles away from <b>97214</b>.<br />"; } // One thing you may want to do with this is create SQL from it. For example, // iterate through the array to create SQL that is something like: // WHERE zip_code IN ('93001 93002 93004') // and then use that condition in your query to find all pizza joints or // whatever you're using it for. Make sense? Hope so. echo "<br /><i>get_zips_in_range() executed in <b>".$z->last_time."</b> seconds.</i><br />"; } // And one more example of using the class to simply get the information about // a zip code. You can then do whatever you want with it. The array returned // from the function has the database field names as the keys. I just do a // couple string converstions to make them more readable. echo '<h3>A sample getting details about a zip code: 97214</h3>'; $details = $z->get_zip_details('97214'); if ($details === false) echo 'Error: '.$z->last_error; else { foreach ($details as $key => $value) { $key = str_replace('_',' ',$key); $key = ucwords($key); echo "$key: $value<br />"; } } ?> </body> </html> zipcode.class.php <?php /******************************************************************************* * ZIP Code and Distance Claculation Class ******************************************************************************* * Author: Micah Carrick * Email: email@micahcarrick.com * Website: http://www.micahcarrick.com * * File: zipcode.class.php * Version: 1.2.0 * Copyright: (c) 2005 - Micah Carrick * You are free to use, distribute, and modify this software * under the terms of the GNU General Public License. See the * included license.txt file. * ******************************************************************************* * VERION HISTORY: * v1.2.0 [Oct 22, 2006] - Using a completely new database based on user contributions which resolves many data bugs. - Added sorting to get_zips_in_range() - Added ability to include/exclude the base zip from get_zips_in_range() * v1.1.0 [Apr 30, 2005] - Added Jeff Bearer's code to make it MUCH faster! * v1.0.1 [Apr 22, 2005] - Fixed a typo * v1.0.0 [Apr 12, 2005] - Initial Version * ******************************************************************************* * DESCRIPTION: * A PHP Class and MySQL table to find the distance between zip codes and * find all zip codes within a given mileage or kilometer range. * ******************************************************************************* */ // constants for setting the $units data member define('_UNIT_MILES', 'm'); define('_UNIT_KILOMETERS', 'k'); // constants for passing $sort to get_zips_in_range() define('_ZIPS_SORT_BY_DISTANCE_ASC', 1); define('_ZIPS_SORT_BY_DISTANCE_DESC', 2); define('_ZIPS_SORT_BY_ZIP_ASC', 3); define('_ZIPS_SORT_BY_ZIP_DESC', 4); // constant for miles to kilometers conversion define('_M2KM_FACTOR', 1.609344); class zipcode_class { var $last_error = ""; // last error message set by this class var $last_time = 0; // last function execution time (debug info) var $units = _UNIT_MILES; // miles or kilometers var $decimals = 2; // decimal places for returned distance function get_distance($zip1, $zip2) { // returns the distance between to zip codes. If there is an error, the // function will return false and set the $last_error variable. $this->chronometer(); // start the clock if ($zip1 == $zip2) return 0; // same zip code means 0 miles between. // get details from database about each zip and exit if there is an error $details1 = $this->get_zip_point($zip1); $details2 = $this->get_zip_point($zip2); if ($details1 == false) { $this->last_error = "No details found for zip code: $zip1"; return false; } if ($details2 == false) { $this->last_error = "No details found for zip code: $zip2"; return false; } // calculate the distance between the two points based on the lattitude // and longitude pulled out of the database. $miles = $this->calculate_mileage($details1[0], $details2[0], $details1[1], $details2[1]); $this->last_time = $this->chronometer(); if ($this->units == _UNIT_KILOMETERS) return round($miles * _M2KM_FACTOR, $this->decimals); else return round($miles, $this->decimals); // must be miles } function get_zip_details($zip) { // This function pulls the details from the database for a // given zip code. $sql = "SELECT lat AS lattitude, lon AS longitude, city, county, state_prefix, state_name, area_code, time_zone FROM zip_code WHERE zip_code='$zip'"; $r = mysql_query($sql); if (!$r) { $this->last_error = mysql_error(); return false; } else { $row = mysql_fetch_array($r, MYSQL_ASSOC); mysql_free_result($r); return $row; } } function get_zip_point($zip) { // This function pulls just the lattitude and longitude from the // database for a given zip code. $sql = "SELECT lat, lon from zip_code WHERE zip_code='$zip'"; $r = mysql_query($sql); if (!$r) { $this->last_error = mysql_error(); return false; } else { $row = mysql_fetch_array($r); mysql_free_result($r); return $row; } } function calculate_mileage($lat1, $lat2, $lon1, $lon2) { // used internally, this function actually performs that calculation to // determine the mileage between 2 points defined by lattitude and // longitude coordinates. This calculation is based on the code found // at http://www.cryptnet.net/fsp/zipdy/ // Convert lattitude/longitude (degrees) to radians for calculations $lat1 = deg2rad($lat1); $lon1 = deg2rad($lon1); $lat2 = deg2rad($lat2); $lon2 = deg2rad($lon2); // Find the deltas $delta_lat = $lat2 - $lat1; $delta_lon = $lon2 - $lon1; // Find the Great Circle distance $temp = pow(sin($delta_lat/2.0),2) + cos($lat1) * cos($lat2) * pow(sin($delta_lon/2.0),2); $distance = 3956 * 2 * atan2(sqrt($temp),sqrt(1-$temp)); return $distance; } function get_zips_in_range($zip, $range, $sort=1, $include_base) { // returns an array of the zip codes within $range of $zip. Returns // an array with keys as zip codes and values as the distance from // the zipcode defined in $zip. $this->chronometer(); // start the clock $details = $this->get_zip_point($zip); // base zip details if ($details == false) return false; // This portion of the routine calculates the minimum and maximum lat and // long within a given range. This portion of the code was written // by Jeff Bearer (http://www.jeffbearer.com). This significanly decreases // the time it takes to execute a query. My demo took 3.2 seconds in // v1.0.0 and now executes in 0.4 seconds! Greate job Jeff! // Find Max - Min Lat / Long for Radius and zero point and query // only zips in that range. $lat_range = $range/69.172; $lon_range = abs($range/(cos($details[0]) * 69.172)); $min_lat = number_format($details[0] - $lat_range, "4", ".", ""); $max_lat = number_format($details[0] + $lat_range, "4", ".", ""); $min_lon = number_format($details[1] - $lon_range, "4", ".", ""); $max_lon = number_format($details[1] + $lon_range, "4", ".", ""); $return = array(); // declared here for scope $sql = "SELECT zip_code, lat, lon FROM zip_code "; if (!$include_base) $sql .= "WHERE zip_code <> '$zip' AND "; else $sql .= "WHERE "; $sql .= "lat BETWEEN '$min_lat' AND '$max_lat' AND lon BETWEEN '$min_lon' AND '$max_lon'"; $r = mysql_query($sql); if (!$r) { // sql error $this->last_error = mysql_error(); return false; } else { while ($row = mysql_fetch_row($r)) { // loop through all 40 some thousand zip codes and determine whether // or not it's within the specified range. $dist = $this->calculate_mileage($details[0],$row[1],$details[1],$row[2]); if ($this->units == _UNIT_KILOMETERS) $dist = $dist * _M2KM_FACTOR; if ($dist <= $range) { $return[str_pad($row[0], 5, "0", STR_PAD_LEFT)] = round($dist, $this->decimals); } } mysql_free_result($r); } // sort array switch($sort) { case _ZIPS_SORT_BY_DISTANCE_ASC: asort($return); break; case _ZIPS_SORT_BY_DISTANCE_DESC: arsort($return); break; case _ZIPS_SORT_BY_ZIP_ASC: ksort($return); break; case _ZIPS_SORT_BY_ZIP_DESC: krsort($return); break; } $this->last_time = $this->chronometer(); if (empty($return)) return false; return $return; } function chronometer() { // chronometer function taken from the php manual. This is used primarily // for debugging and anlyzing the functions while developing this class. $now = microtime(TRUE); // float, in _seconds_ $now = $now + time(); $malt = 1; $round = 7; if ($this->last_time > 0) { /* Stop the chronometer : return the amount of time since it was started, in ms with a precision of 3 decimal places, and reset the start time. We could factor the multiplication by 1000 (which converts seconds into milliseconds) to save memory, but considering that floats can reach e+308 but only carry 14 decimals, this is certainly more precise */ $retElapsed = round($now * $malt - $this->last_time * $malt, $round); $this->last_time = $now; return $retElapsed; } else { // Start the chronometer : save the starting time $this->last_time = $now; return 0; } } }
  4. Should I be using mysql_query() and mysql_fetch_array()? I know this is something really small. All i'm trying to do is get the rows from that zip code column after the calculation has been made.
  5. If you are using an FTP program like smart ftp or cute ftp you can rightclick on the file and select permissions. Dreamweaver has the same thing. Also, if your hosting service has a control panel you can usually go to where the files are and you will see like a 644 or whatever next to the file. Click on that and you should be able to change it there too. `Jake
  6. <?php // Read POST request params into global vars $to = $_POST['to']; $from = $_POST['from']; $subject = $_POST['subject']; $message = $_POST['message']; // Obtain file upload vars $fileatt = $_FILES['fileatt']['tmp_name']; $fileatt_type = $_FILES['fileatt']['type']; $fileatt_name = $_FILES['fileatt']['name']; $headers = "From: $from"; if (is_uploaded_file($fileatt)) { // Read the file to be attached ('rb' = read binary) $file = fopen($fileatt,'rb'); $data = fread($file,filesize($fileatt)); fclose($file); // Generate a boundary string $semi_rand = md5(time()); $mime_boundary = "==Multipart_Boundary_x{$semi_rand}x"; // Add the headers for a file attachment $headers .= "\nMIME-Version: 1.0\n" . "Content-Type: multipart/mixed;\n" . " boundary=\"{$mime_boundary}\""; // Add a multipart boundary above the plain message $message = "This is a multi-part message in MIME format.\n\n" . "--{$mime_boundary}\n" . "Content-Type: text/plain; charset=\"iso-8859-1\"\n" . "Content-Transfer-Encoding: 7bit\n\n" . $message . "\n\n"; // Base64 encode the file data $data = chunk_split(base64_encode($data)); // Add file attachment to the message $message .= "--{$mime_boundary}\n" . "Content-Type: {$fileatt_type};\n" . " name=\"{$fileatt_name}\"\n" . "Content-Disposition: attachment;\n" . " filename=\"{$fileatt_name}\"\n" . "Content-Transfer-Encoding: base64\n\n" . $data . "\n\n" . "--{$mime_boundary}--\n"; } // Send the message $ok = @mail($to, $subject, $message, $headers); if ($ok) { echo "<p>Mail sent! Yay PHP!</p>"; } else { echo "<p>Mail could not be sent. Sorry!</p>"; } ?> And that's how we send emails with file attachments in PHP!
  7. Sometimes if you have the code as <? rather that <?php the page will come up blank as well.
  8. Do you mean like $DOCUMENT_ROOT = $_SERVER['DOCUMENT_ROOT'];
  9. How do I echo out these rows I am selecting from the zipcode column? function inradius($zip,$radius) { global $db; $query="SELECT * FROM zipData WHERE zipcode='$zip'"; $db->query($query); if($db->affected_rows()<>0) { $db->next_record(); $lat=$db->f("lat"); $lon=$db->f("lon"); $query="SELECT zipcode FROM zipData WHERE (POW((69.1*(lon-\"$lon\")*cos($lat/57.3)),\"2\")+POW((69.1*(lat-\"$lat\")),\"2\"))<($radius*$radius) "; $db->query($query); if($db->affected_rows()<>0) { while($db->next_record()) { $zipArray[$i]=$db->f("zipcode"); $i++; } } }else{ return "Zip Code not found"; } return $zipArray; } // end func } // end class
  10. The PHP MD5() function does not encrypt a string in the same way as the standard *nix MD5SUM function. If you want to access an encrypted string in a MySQL database from different programs in *nix, and also from PHP, use the MySQL MD5() function, as in: UPDATE users SET pwd=md5('mypass') WHERE user='myuser'; This will generate the same encrypted string as in PHP md5('mypass').
  11. This is one way, it checks for expressions. <?php $email="john@zend.com"; if(!eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9- ]+)*(\.[a-z]{2,3})$", $email) { echo "The e-mail was not valid"; } else { echo "The e-mail was valid"; } ?>
  12. I am wanting to add a table to my MYsQL Database. With the colums Dealer, Address, City, State, Zip. I am wanting to use this code to find the dealers within a certain radius, depending on what zip code the user types in. [attachment deleted by admin]
  13. Am I in the wrong place looking for help on this?
  14. No, I need some direction. I don't know where to start. I was hoping someone could help walk me through some of it.
  15. Could someone please help me with this?
  16. How could I add onto this code to have it retrieve all of the zip codes within radius from another table?
  17. Hello, I have this code that returns the distance between two zip codes and will return a radius of zips within so many miles. I am wanting to add onto this code to have it select from a new table that I have all of the rows of zip codes within that range. This new table would have name, address, zip, ect. <?php /* vim: set expandtab tabstop=4 shiftwidth=4: */ // +----------------------------------------------------------------------+ // | Filname: | // +----------------------------------------------------------------------+ // | Copyright (c) http://www.sanisoft.com | // +----------------------------------------------------------------------+ // | Description: | // +----------------------------------------------------------------------+ // | Authors: Original Author <author@example.com> | // | Your Name <you@example.com> | // +----------------------------------------------------------------------+ // // $Id$ include_once ("db_mysql.inc"); include_once ("phpZipLocator.php"); $db = new db_sql; $zipLoc = new zipLocator; $zipOne = 71075; $zipTwo = 23456; $distance = $zipLoc->distance($zipOne,$zipTwo); echo "The distance between $zipOne and $zipTwo is $distance Miles<br>"; $radius = 90; $zipArray = $zipLoc->inradius($zipOne,$radius); echo "There are ",count($zipArray)." Zip codes within $radius Miles of $zipOne"; <?php /* vim: set expandtab tabstop=4 shiftwidth=4: */ // +----------------------------------------------------------------------+ // | Filname: phpZipLocator.php | // +----------------------------------------------------------------------+ // | Copyright (c) http://www.sanisoft.com | // +----------------------------------------------------------------------+ // | License (c) This software is licensed under LGPL | // +----------------------------------------------------------------------+ // | Description: A simple class for finding distances between two zip | // | codes, The distance calculation is based on Zipdy package found | // | at http://www.cryptnet.net/fsp/zipdy/ written by V. Alex Brennen | // | <vab@cryptnet.net> | // | You can also do radius calculations to find all the zipcodes within | // | the radius of x miles | // +----------------------------------------------------------------------+ // | Authors: Dr Tarique Sani <tarique@sanisoft.com> | // | Girish Nair <girish@sanisoft.com> | // +----------------------------------------------------------------------+ // // $Id$ class zipLocator { /** * Short description. * This method returns the distance in Miles between two zip codes * Detail description * This method returns the distance in Miles between two zip codes, if either of the zip code is not found and error is retruned * @param zipOne - The first zip code * @param zipTwo - The second zip code * @global db - the database object * @since 1.0 * @access public * @return string * @update */ function distance($zipOne,$zipTwo) { global $db; $query = "SELECT * FROM zipData WHERE zipcode = $zipOne"; $db->query($query); if(!$db->nf()) { return "First Zip Code not found"; }else{ $db->next_record(); $lat1 = $db->f("lat"); $lon1 = $db->f("lon"); } $query = "SELECT * FROM zipData WHERE zipcode = $zipTwo"; $db->query($query); if(!$db->nf()) { return "Second Zip Code not found"; }else{ $db->next_record(); $lat2 = $db->f("lat"); $lon2 = $db->f("lon"); } /* Convert all the degrees to radians */ $lat1 = $this->deg_to_rad($lat1); $lon1 = $this->deg_to_rad($lon1); $lat2 = $this->deg_to_rad($lat2); $lon2 = $this->deg_to_rad($lon2); /* Find the deltas */ $delta_lat = $lat2 - $lat1; $delta_lon = $lon2 - $lon1; /* Find the Great Circle distance */ $temp = pow(sin($delta_lat/2.0),2) + cos($lat1) * cos($lat2) * pow(sin($delta_lon/2.0),2); $EARTH_RADIUS = 3956; $distance = $EARTH_RADIUS * 2 * atan2(sqrt($temp),sqrt(1-$temp)); return $distance; } // end func /** * Short description. * Converts degrees to radians * @param deg - degrees * @global none * @since 1.0 * @access private * @return void * @update */ function deg_to_rad($deg) { $radians = 0.0; $radians = $deg * M_PI/180.0; return($radians); } /** * Short description. * This method retruns an array of zipcodes found with the radius supplied * Detail description * This method returns an array of zipcodes found with the radius supplied in miles, if the zip code is invalid an error string is returned * @param zip - The zip code * @param radius - The radius in miles * @global db - instance of database object * @since 1.0 * @access public * @return array/string * @update date time */ function inradius($zip,$radius) { global $db; $query="SELECT * FROM zipData WHERE zipcode='$zip'"; $db->query($query); if($db->affected_rows()<>0) { $db->next_record(); $lat=$db->f("lat"); $lon=$db->f("lon"); $query="SELECT zipcode FROM zipData WHERE (POW((69.1*(lon-\"$lon\")*cos($lat/57.3)),\"2\")+POW((69.1*(lat-\"$lat\")),\"2\"))<($radius*$radius) "; $db->query($query); if($db->affected_rows()<>0) { while($db->next_record()) { $zipArray[$i]=$db->f("zipcode"); $i++; } } }else{ return "Zip Code not found"; } return $zipArray; } // end func } // end class ?>
  18. I found this. It makes it to where ppl are unable to right click. <HEAD> <SCRIPT LANGUAGE="JavaScript1.1"> <!-- Original: Martin Webb (martin@irt.org) --> <!-- This script and many more are available free online at --> <!-- The JavaScript Source!! http://javascript.internet.com --> <!-- Begin function right(e) { if (navigator.appName == 'Netscape' && (e.which == 3 || e.which == 2)) return false; else if (navigator.appName == 'Microsoft Internet Explorer' && (event.button == 2 || event.button == 3)) { alert("Sorry, you do not have permission to right click."); return false; } return true; } document.onmousedown=right; document.onmouseup=right; if (document.layers) window.captureEvents(Event.MOUSEDOWN); if (document.layers) window.captureEvents(Event.MOUSEUP); window.onmousedown=right; window.onmouseup=right; // End --> </script> </HEAD>
  19. Yea, I just need to make it harder for people to get the information though.
  20. Does anyone know how to make it to where no one can right click and copy a bunch of important data off of you page?
  21. mysql_connect("localhost","myuser","mypass"); mysql_select_db("mydatabase"); $now = strtotime(date("Y/m/d H:i:s")); $expire = $now + (60 * 60 * 24 * 30); $values = "'$username','$first','$last','$pass',1,'$now','$expire'"; $cols = "username,first,last,password,billing,created,expire"; $id = db_insert ("users", $cols, $values); mysql_close(); echo "<br><br> Account #$id Created"; $_SESSION ["cur_user"] = $id; echo "<Br><Br>Saving contact Info Record Number: "; I tried mysql_insert, i get :Call to undefined function mysql_insert()
  22. I got some code that had the function db_connect and I had to change it to mysql_connect for in to work. I am having trouble with db_insert, what would be another function that would replace this?
×
×
  • 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.