SQL选择列zipcode中的数据与数组中的数据匹配的任何行?

时间:2013-03-21 23:33:59

标签: php sql database geolocation

好的问题是我在702web.com/tutors网站上进行自定义地理定位

使用内页进行搜索,因为未完成主页搜索。

我将它设置为用户不输入邮政编码的位置,主题是任何它将显示所有导师,还有没有输入邮政编码的地方,他们选择一个主题然后所有教导该主题的导师将被显示,我也有输入邮政编码的地方,用户选择该邮政编码显示的任何导师,第四个也是最后一个是用户输入邮政编码和主题然后所有教导该主题的导师并在该邮政编码中显示。

这样做很简单,但为了使第三次和第四次稍微复杂一点,我选择了用户输入的邮政编码半径40英里范围内的所有邮政编码(使用包含所有邮政编码的表格和纬度和经度)。找到该半径内的所有邮政编码都有效。

我的问题是 如何使用数组查询该数据库?因为该半径中的所有邮政编码都放在一个数组中,我怎么能告诉使用SELECT语句“SELECT * FROM wp_testimonials WHERE postcode ='”。$这是我的阵列??“'和find_in_set('”。$ _ REQUEST ['subject']。“',subject)”

结果页面的代码

<?php
        if(isset($_REQUEST['send']) OR !empty($_REQUEST['zipcode'])) {
            if(!preg_match('/^[0-9]{5}$/', $_REQUEST['zipcode'])) {

                    include('search_page.php');

            }
            else {

        //connect to db server; select database
                $link = mysql_connect('t0tors102938.db.7131821.hostedresource.com', 't0tors102938', 'aL8#Jfo89!') or die('Cannot connect to database server');
                mysql_select_db('t0tors102938') or die('Cannot select database');

                //query for coordinates of provided ZIP Code
                if(!$rs = mysql_query("SELECT * FROM wp_us_zipcodes WHERE zip_code = '$_REQUEST[zipcode]'")) {
                    echo "<p><strong>There was a database error attempting to retrieve your ZIP Code.</strong> Please try again.</p>\n";
                }
                else {
                    if(mysql_num_rows($rs) == 0) {
                        echo "<p><strong>No database match for provided ZIP Code.</strong> Please enter a new ZIP Code.</p>\n"; 
                    }
                    else {
                        //if found, set variables
                        $row = mysql_fetch_array($rs);
                        $lat1 = $row['latitude'];
                        $lon1 = $row['longitude'];
                        $d = 40;
                        $r = 3959;

                        //compute max and min latitudes / longitudes for search square
                        $latN = rad2deg(asin(sin(deg2rad($lat1)) * cos($d / $r) + cos(deg2rad($lat1)) * sin($d / $r) * cos(deg2rad(0))));
                        $latS = rad2deg(asin(sin(deg2rad($lat1)) * cos($d / $r) + cos(deg2rad($lat1)) * sin($d / $r) * cos(deg2rad(180))));
                        $lonE = rad2deg(deg2rad($lon1) + atan2(sin(deg2rad(90)) * sin($d / $r) * cos(deg2rad($lat1)), cos($d / $r) - sin(deg2rad($lat1)) * sin(deg2rad($latN))));
                        $lonW = rad2deg(deg2rad($lon1) + atan2(sin(deg2rad(270)) * sin($d / $r) * cos(deg2rad($lat1)), cos($d / $r) - sin(deg2rad($lat1)) * sin(deg2rad($latN))));



                        //find all coordinates within the search square's area
                        //exclude the starting point and any empty city values
                        $query = "SELECT * FROM wp_us_zipcodes WHERE (latitude <= $latN AND latitude >= $latS AND longitude <= $lonE AND longitude >= $lonW) AND city != '' ORDER BY state, city, latitude, longitude";
                        if(!$rs = mysql_query($query)) {
                            echo "<p><strong>There was an error selecting nearby ZIP Codes from the database.</strong></p>\n";
                        }
                        elseif(mysql_num_rows($rs) == 0) {
                            echo "<p><strong>No nearby ZIP Codes located within the distance specified.</strong> Please try a different distance.</p>\n";                               
                        }
                        else {
                            //output all matches to screen
                            while($row = mysql_fetch_array($rs)) {
                                foreach($row['zip_code'] as $rows) {
                                    $queryzipcodes[] = $rows;

                                }
                            }
                            $sqlzip = implode(',',$queryzipcodes);

                            echo "$queryzipcodes";
                            //echo 'ok';

                                if($_REQUEST['subject']!='' && $_REQUEST['zipcode']!='')
            {
            $sql="SELECT * FROM wp_testimonials WHERE postcode IN ($sqlzip) AND find_in_set( '".$_REQUEST['subject']."', subject )";
            }elseif($_REQUEST['subject']!='') {
            $sql="SELECT * FROM wp_testimonials WHERE find_in_set( '".$_REQUEST['subject']."', subject )";
            }
            elseif($_REQUEST['zipcode']!='') {
            $sql="SELECT * FROM wp_testimonials WHERE postcode = '".$_REQUEST['zipcode']."'";
            }
            else
            {
            $sql="SELECT * FROM wp_testimonials";
            }
        //echo $sql;

        $tutors = $wpdb->get_results($sql);

                $count = 0;

                print('<br>');
                foreach ($tutors as $tutor)
                {
                    $odd = $count%2;
                   if ($odd == 1)
                   {
                        $bgcolor='#fafafa';
                   }elseif ($odd == 0)
                   {
                        $bgcolor='#f0f0f0';
                   }
                     $sql3="SELECT sfimgurl FROM wp_testimonials WHERE testid='".$tutor->testid."'";
                     $res3=mysql_query($sql3);
                     $data3=mysql_fetch_assoc($res3);

                     $blogurl = get_bloginfo('wpurl');
                     $imgsrc =  '/wp-content/uploads/';
                     $tutorimg =  $data3['sfimgurl'];

                     print('<table width="100%" style="border-radius: 10px;" bgcolor="'.$bgcolor.'">');

                     print('<tr height="145px"><td width="110px" style="padding: 10px 5px 10px 10px; vertical-align: top; "><div style="height:145px; overflow:hidden; float: left; padding-right: 10px; border: dotted; border-width: 0 1px 0 0"><img src="'.$blogurl.'' .$imgsrc.'' .$tutorimg.'" width="100" height="145" />');

                     print('</div></td>');
                     print('<td valign="top" width="150px" style="float:left; padding-left: 5px; padding-top:5px;"><div style="float: left; font-size:12px;"><strong>TUTOR:<br><a href="?page_id=175&tid=' .$tutor->testid. '">'.$tutor->clientname.'</a><br></strong><br>');


                $subj=$tutor->subject;
                $arrr_subject=explode(',', $subj);
                for($i=0;$i<3;$i++) {
                //$i<count($arrr_subject)
                    $sql2="select * from wp_tutorcat WHERE subid='".$arrr_subject[$i]."'";
                    $res2=mysql_query($sql2);
                    $data2=mysql_fetch_assoc($res2);
                    $subject2 = (strlen($data2['subject']) > 20) ? substr($data2['subject'],0,17).'...' : $data2['subject'];
                    echo $subject2.'<br>';

                }


                     //print('<br> '.$tutor->text_full.'<br/><br/>');
                     print('<br><strong>Zip Code: '.$tutor->postcode.'</strong></div></td>');


                 print('<td width="350px" style="padding-left:10px; padding-top: 5px; vertical-align: top; border: dotted; border-width: 0 0 0 1px;"><div style="float: left; font-size: 12px; position: relative; padding-right: 5px; ">');
                $idnum=$tutor->testid;
//$bio=$data['text_full'];
$sql3="SELECT text_full FROM wp_testimonials WHERE testid='".$idnum."'";
$res3=mysql_query($sql3);
$data3=mysql_fetch_assoc($res3);
$ses = "'s";
$bio = (strlen($data3['text_full']) > 103) ? substr($data3['text_full'],0,100).'...' : $data3['text_full'];
echo '<strong>BIO:</strong>


<br>'.$bio.'<br></div>';


                print('<div align="center"><p style="text-align: center;"><span class="bk-button-wrapper"><a href="?page_id=175&tid=' .$tutor->testid. '" target="_self" class="bk-button red center rounded small" style="margin-top: 15px;">View '.$tutor->clientname.''. $ses . ' Profile</a></span></p></div>');

                print('</td></tr></table>');



                     $count++;


                            }

                        }
                    }
                }
            }
        }


               ?>

4 个答案:

答案 0 :(得分:0)

如果您可以在SELECT查询中使用数组,我很抱歉,但我不相信您可以使用数组直接查询数据库,但您可以循环使用zipcode数组并使用每个zipcode查询数据库:

$zips = array( '41240', '41256', '41202' );
$result = array();

foreach( $zips as $key=>$value ) {

     // Select query with $value
     // Save result to $result[ $key ]

}
echo '<pre>' . print_r( $result, 1 ) . '</pre>';

→这就是你要找的东西吗?

答案 1 :(得分:0)

您可以执行类似的操作将数组传递给SQL查询:

<?php
  $zipcodes  =  $_REQUEST["zipcode"];
  if( valid_zipcodes($zipcodes) ) // validate the data before query
  {
     $zipcodes  =  str_replace(
        array(']','['), 
        array(')','('), 
        json_encode($zipcodes) );
     mysql_query("SELECT * FROM wp_testimonials WHERE postcode IN $zipcodes;");
     // any other job
  }
?>

您的查询将如下:

SELECT * 
FROM wp_testimonials 
WHERE postcode IN ('123456', '987654');

答案 2 :(得分:0)

执行此操作的最佳方法是在2个表中使用SQL连接 下表用于在使用PDO的SQL查询中使用Haversine公式查找给定半径内的导师

tables

// Prepare statement
    $stmt = $dbh->prepare("SELECT `tutors`.`name`, `tutors`.`zip`,`uszips`.`city`,`uszips`.`latitude`,`uszips`.`longitude`,( 3959 * acos( cos( radians(?) ) * cos( radians( `uszips`.`latitude` ) ) * cos( radians( `uszips`.`longitude` ) - radians(?) ) + sin( radians(?) ) * sin( radians( `uszips`.`latitude`) ) ) )  AS distance  FROM `uszips`, `tutors`  WHERE (`uszips`.`zip` =`tutors`.`zip`) HAVING distance < ?  ORDER BY distance ");
// Assign parameters
$stmt->bindParam(1,$center_lat);
$stmt->bindParam(2,$center_lng);
$stmt->bindParam(3,$center_lat);
$stmt->bindParam(4,$radius);
//Execute query
$stmt->setFetchMode(PDO::FETCH_ASSOC);
$stmt->execute();
// Iterate through the rows, adding XML nodes for each
while($row = $stmt->fetch()) {
    echo $row['city'].",".$row['zip'].",".$row['name'].",".$row['distance'].",".$row['latitude'].",".$row['longitude'];
}

其中$center_lat$center_lng是用户的坐标,$radius是距离(英里)。

答案 3 :(得分:0)

好的家伙我明白了。

从头到尾想出这个,总共需要12个小时的工作时间。

显示结果的代码和主页的表格行动

<?php
    /*
        Template Name: Tutor Locator Template
    */
?>

<?php get_header(); ?>

    <div id="primary">
 <div class="small-search-tutor">

<div class="small-search-tutor-box">

 <?php
 include('post_search.php');
 ?>

</div>
</div>

        <div id="content" role="main">

            <?php while ( have_posts() ) : the_post(); ?>

                <?php get_template_part( 'content', 'page' ); ?>

<br />

<?php

// Create page variables
$r = 50;
$z = NULL;
$stores = NULL;
$Errors = NULL;

// Establish DB connection
$dbc = mysql_connect ('t0tors102938.db.7131821.hostedresource.com', 't0tors102938', 'aL8#Jfo89!');
mysql_select_db ('t0tors102938', $dbc);

// Declare page functions
function Dist ($lat_A, $long_A, $lat_B, $long_B) {

  $distance = sin(deg2rad($lat_A))
  * sin(deg2rad($lat_B))
  + cos(deg2rad($lat_A))
  * cos(deg2rad($lat_B))
  * cos(deg2rad($long_A - $long_B));

$distance = (rad2deg(acos($distance))) * 69.09;
return $distance;

}

### Handle form if submitted
if (isset ($_REQUEST['send']) OR !empty($_REQUEST['zipcode'])) {

// Validate Zip code field
 if (!empty ($_REQUEST['zipcode']) && is_numeric ($_REQUEST['zipcode'])) {

$z = (int)$_REQUEST['zipcode'];

// Verify zip code exists
 $query = "SELECT lat, lon FROM zip_codes WHERE zip = '$z'";
 $result = mysql_query ($query);

 if (mysql_num_rows ($result) == 1) {
  $zip = mysql_fetch_assoc ($result);
 } else {
  $Errors = '<p>The zip code you entered was not found!</p>';
}

 }elseif (empty ($_REQUEST['zipcode'])){
$query = "SELECT lat, lon FROM zip_codes";
  $result = mysql_query ($query);

 if (mysql_num_rows ($result) == 1) {
  $zip = mysql_fetch_assoc ($result);
 } else {
  $Errors = '<p>The zip code you entered was not found!</p>';
}

}



// Proceed if no errors were found


// Retrieve coordinates of the stores
$tutors = array();
$r = 50;
if(empty($_REQUEST['zipcode']) && $_REQUEST['subject']!='Any'){

$query = "SELECT * FROM wp_testimonials WHERE find_in_set( '".$_REQUEST['subject']."', subject )";  
}

 elseif($_REQUEST['subject']!='Any'){
$query = "SELECT testid, clientname, phone, email, subject, text_full, hourly_rate, postcode, lat, lon
FROM wp_testimonials
INNER JOIN zip_codes
ON wp_testimonials.postcode = zip_codes.zip
AND find_in_set( '".$_REQUEST['subject']."', subject )";
}

 elseif(empty($_REQUEST['zipcode']) && $_REQUEST['subject']='Any'){
$query = "SELECT * FROM wp_testimonials";   
}

 elseif(!empty($_REQUEST['zipcode']) && $_REQUEST['subject']='Any'){
$query = "SELECT testid, clientname, phone, email, subject, text_full, hourly_rate, postcode, lat, lon
FROM wp_testimonials
INNER JOIN zip_codes
ON wp_testimonials.postcode = zip_codes.zip";   
}

$result = mysql_query ($query);

// Go through and check all stores
while ($row = mysql_fetch_assoc ($result)) {

  // Separate closest stores
  $distance = Dist ($row['lat'], $row['lon'], $zip['lat'], $zip['lon']);

  // Check if store is in radius
  if ($distance <= $r) {

    $tutors[] = array (
      'testid'      => $row['testid'],
      'clientname'      => $row['clientname'],
      'email'   => $row['email'],
      'subject'      => $row['subject'],
      'postcode'    => $row['postcode'],
      'text_full'     => $row['text_full'],
      'phone'     => $row['phone'],
      'hourly_rate'     => $row['hourly_rate']
     );

   }

  }

 } else {
  $Errors = ($Errors) ? $Errors : '<p>Errors were found please try again!</p>';
}


?>


<?php

if (isset ($tutors)) {

  if (!empty ($tutors)) {
$count = 0;
   //echo '<p><strong>' . count ($tutors) . ' results were found.</strong></p>';
    foreach ($tutors as $value) {
                $odd = $count%2;
                   if ($odd == 1)
                   {
                        $bgcolor='#fafafa';
                   }elseif ($odd == 0)
                   {
                        $bgcolor='#f0f0f0';
                   }    
    $sql3="SELECT sfimgurl FROM wp_testimonials WHERE testid='".$value['testid']."'";
                     $res3=mysql_query($sql3);
                     $data3=mysql_fetch_assoc($res3);

                     $blogurl = get_bloginfo('wpurl');
                     $imgsrc =  '/wp-content/uploads/';
                     $tutorimg =  $data3['sfimgurl'];


echo '<table width="100%" style="border-radius: 10px;" bgcolor="'.$bgcolor.'">';                 
echo '<tr height="145px"><td width="110px" style="padding: 10px 5px 10px 10px; vertical-align: top; "><div style="height:145px; overflow:hidden; float: left; padding-right: 10px; border: dotted; border-width: 0 1px 0 0"><img src="'.$blogurl.'' .$imgsrc.'' .$tutorimg.'" width="100" height="145" /><div></td>';       

echo '<td valign="top" width="150px" style="float:left; padding-left: 5px; padding-top:5px;"><div style="float: left; font-size:12px;"><strong>TUTOR:<br><a href="?page_id=175&tid=' .$value['testid']. '">'.$value['clientname'].'</a><br></strong><br>';

$arrr_subject = array();
                $arrr_subject=explode(',', $value['subject']);
                for($i=0;$i<3;$i++) {
                    $sql2="SELECT * FROM wp_tutorcat WHERE subid='".$arrr_subject[$i]."'";
                    $results2=mysql_query($sql2);
                    $row2=mysql_fetch_assoc($results2);
                    $subject2 = (strlen($row2['subject']) > 20) ? substr($row2['subject'],0,17).'...' : $row2['subject'];

                if($subject2!=''){
                echo $subject2.'<br>';  
                }else{
                //do nothing
                }
                }

    // echo '<br />Hourly Rate: ' . $value['hourly_rate'] . '<br />';
     echo '<br><strong>Zip Code: '.$value['postcode'].'</strong></div></td>';           
    echo '<td width="350px" style="padding-left:10px; padding-top: 5px; vertical-align: top; border: dotted; border-width: 0 0 0 1px;"><div style="float: left; font-size: 12px; position: relative; padding-right: 5px; ">';
  $ses = "'s";
  $bio = (strlen($value['text_full']) > 103) ? substr($value['text_full'],0,100).'...' : $value['text_full'];


  echo '<strong>BIO:</strong><br>'.$bio.'<br></div>';


  echo '<div align="center"><p style="text-align: center;"><span class="bk-button-wrapper"><a href="?page_id=175&tid=' .$value['testid']. '" target="_self" class="bk-button red center rounded small" style="margin-top: 15px;">View '.$value['clientname'].''. $ses . ' Profile</a></span></p></div>';



  echo '</td></tr></table>';
    $count++;
 }

  } else {
echo '<p><strong>No results found</strong></p>';
  }



}

?>

<?php endwhile; // end of the loop. ?>





        </div><!-- #content -->

    </div><!-- #primary -->



<?php get_sidebar(); ?>

搜索所有内页的条码

<?php 
//print_r($_REQUEST);
if($_REQUEST['send']=='send')
{
if($_REQUEST['subject']!='Any' AND empty($_REQUEST['zipcode'])){
header("Location:?page_id=275&subject=".$_REQUEST['subject']);  
}
elseif ($_REQUEST['subject']=='Any' AND !empty($_REQUEST['zipcode'])){
header("Location:?page_id=410&zipcode=".$_REQUEST['zipcode']."&subject=".$_REQUEST['subject']); 
}
elseif (empty($_REQUEST['zipcode'])){
header("Location:?page_id=275&subject=");
}
else{
header("Location:?page_id=410&zipcode=".$_REQUEST['zipcode']."&subject=".$_REQUEST['subject']);
}
}
?>

 <form method="post" action="">
 <div style="display:inline-block; width:60px; font-size:12px; vertical-align:top; padding-top:7px;">ZIP
 <input type="text" id="zip" name="zipcode" style="width:100px; margin-top:-10px;"/>
 </div>
 <div style="display:inline-block; width:180px; padding-left:50px; vertical-align:top; padding-top:7px; font-size:12px;">SUBJECT:
 <select name="subject" style="width:180px;">
    <option value="Any">Any</option>
    <?php
$sql="select * from wp_tutorcat";
$res=mysql_query($sql);
while($data=mysql_fetch_array($res))
{
   $rr="select * FROM wp_testimonials WHERE find_in_set( '".$data['subid']."', `subject` )";
   $ff=mysql_query($rr);
   $num=mysql_num_rows($ff);
   if($num>0)
   {
?>
<option value="<?=$data['subid']?>" <?php if(in_array($data['subid'],$arrr)) echo 'selected'?>><?=$data['subject']?></option>

<?php
}
}
?>

</select>




  </div>

  <div style="display:inline-block; vertical-align:top; padding-top:23px; ">
    <input type="hidden" value="send" name="send" />
    <input type="submit" name="search"  value="search"/>

  </div>

</form>

TUTORS DATABASE TABLE SQL

-- phpMyAdmin SQL Dump
-- version 2.11.11.3
-- http://www.phpmyadmin.net
--
-- Host: 0.0.0.0
-- Generation Time: Mar 22, 2013 at 02:58 PM
-- Server version: 5.0.96
-- PHP Version: 5.1.6

SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO";

--
-- Database: `t0tor******`
--

-- --------------------------------------------------------

--
-- Table structure for table `wp_testimonials`
--

DROP TABLE IF EXISTS `wp_testimonials`;
CREATE TABLE IF NOT EXISTS `wp_testimonials` (
  `testid` int(15) NOT NULL auto_increment,
  `clientname` varchar(100) NOT NULL,
  `phone` varchar(20) default NULL,
  `email` varchar(100) NOT NULL,
  `subject` varchar(999) NOT NULL,
  `text_full` varchar(999) NOT NULL,
  `hourly_rate` varchar(20) NOT NULL,
  `package_discount` varchar(20) NOT NULL,
  `group_discount` varchar(20) NOT NULL,
  `sfimgurl` varchar(100) NOT NULL,
  `postcode` varchar(5) NOT NULL,
  `storder` int(5) NOT NULL,
  `featured` varchar(255) NOT NULL,
  PRIMARY KEY  (`testid`),
  KEY `postal` (`postcode`)
) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=17 ;

--
-- Dumping data for table `wp_testimonials`
--

INSERT INTO `wp_testimonials` VALUES(8, 'Jill Mohlman', '', 'Jill@gmail.com', '25,28,34,39,51,66,104', 'Highest Degree: Bachelors in education\r\nCollege:  Brigham Young\r\nYears as a Teacher:  7\r\nYears as a Tutor: 4', '13', '', '', 'Jill-Mohlman.jpg', '79912', 0, 'Yes');
INSERT INTO `wp_testimonials` VALUES(9, 'Heather Severson', '', '', '33,62,89,104,105,107', 'Highest Degree:  Master of Music\r\nCollege:  Brigham Young\r\nYears as a Teacher:  15\r\n\r\nBio:\r\nWith a Masters Degree in Music and a classically trained violinist, Heather believes that each student requires an individual approach to learning.  Heather focuses on each students strengths and weaknesses, then alters her teaching methods to meet a students needs accordingly.  \r\nHighest Degree:  Master of Music', '13', '', '', 'Heather-Seaverson.jpg', '84054', 0, 'No');
INSERT INTO `wp_testimonials` VALUES(10, 'Floyd Fitzgibbons', '', '', '103', 'Name:  Floyd Fitzgibbons\r\nHighest Degree: Certified Insurance Counselor\r\nCollege:  UNLV\r\nYears as a Teacher:  8+\r\nYears as a Tutor: 5+', '18', '', '', 'Floyd-Fitzgibbons.jpg', '89149', 0, 'No');
INSERT INTO `wp_testimonials` VALUES(12, 'Ryan Fitzgibbons', '', '', '40,67', 'An accomplished teacher and tutor, Ryan ranked as one of the highest rated Kaplan Instructors in the nation for SAT and ACT score improvement. His students have gone to every Ivy League school. Many still keep in contact to report their academic successes, even years after the fact. He has received tremendous reviews from students and parents alike for his friendly and patient attitude, and ability to get results.\r\n\r\n-Member: Mensa High IQ Society - \r\n\r\nScored in 99th percentile on SAT & ACT - \r\n\r\nEagle Scout - Nationally ranked Kaplan SAT & ACT Specialist - \r\n\r\n\\"Ryan cares more than any teacher I\\''ve ever met. He loses more sleep anxiously awaiting his students\\'' test results than they do!\\"', '39', '', '', 'Ryan-Fitzgibbons-200x300.jpg', '89129', 0, 'No');
INSERT INTO `wp_testimonials` VALUES(13, 'Royce Seaverson', '', '', '21,23,28,31,34,37,38,41,42,48,49,66,76,77,82,89,105', 'Highest Degree: Masters\r\nCollege:  BYU', '15', '', '', 'Royce-Seaverson.jpg', '84054', 0, 'No');
INSERT INTO `wp_testimonials` VALUES(14, 'Billy Bob', '', '', '103,104', '', '', '', '', '2012/11/how-it-works-191x300.jpg', '79912', 0, '');
INSERT INTO `wp_testimonials` VALUES(16, 'Billy Joel', '702-539-0540', 'nicholas@702web.com', '24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48', 'I am a great Tutor', '11', '', '', 'footer-purchasing.jpg', '89141', 0, 'Yes');

邮政编码列表的部分SQL

在此处获取完整列表http://www.unitedstateszipcodes.org/zip-code-database/

-- phpMyAdmin SQL Dump
-- version 2.11.11.3
-- http://www.phpmyadmin.net
--
-- Host: 
-- Generation Time: Mar 22, 2013 at 04:39 PM
-- Server version: 5.0.96
-- PHP Version: 5.1.6

SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO";

--
-- Database: `t0tors102938`
--

-- --------------------------------------------------------

--
-- Table structure for table `zip_codes`
--

DROP TABLE IF EXISTS `zip_codes`;
CREATE TABLE IF NOT EXISTS `zip_codes` (
  `zip_id` int(11) NOT NULL auto_increment,
  `zip` varchar(5) NOT NULL default '',
  `abbr_state` char(2) NOT NULL default '',
  `lat` varchar(10) NOT NULL default '',
  `lon` varchar(10) NOT NULL default '',
  `city` varchar(50) default NULL,
  `full_state` varchar(50) default NULL,
  PRIMARY KEY  (`zip_id`),
  UNIQUE KEY `zip` (`zip`)
) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=42523 ;

--
-- Dumping data for table `zip_codes`
--

INSERT INTO `zip_codes` VALUES(1, '501', 'NY', '40.81', '-73.04', 'Holtsville', 'NY');
INSERT INTO `zip_codes` VALUES(2, '544', 'NY', '40.81', '-73.04', 'Holtsville', 'NY');
INSERT INTO `zip_codes` VALUES(3, '601', 'PR', '18.16', '-66.72', 'Adjuntas', 'PR');
INSERT INTO `zip_codes` VALUES(4, '602', 'PR', '18.38', '-67.18', 'Aguada', 'PR');
INSERT INTO `zip_codes` VALUES(20, '631', 'PR', '18.19', '-66.82', 'Castaner', 'PR');