1

わかりました。質問は、サイト 702web.com/tutors でカスタム ジオロケーションを行っていることです。

ホームページ検索は行っておりませんので、検索は内ページをご利用ください。

ユーザーが郵便番号を入力せず、件名がすべてのチューターを表示するようにセットアップし、郵便番号が入力されていない場所にセットアップし、サブジェクトを選択すると、そのサブジェクトを教えるすべてのチューターが表示されます。郵便番号が入力され、ユーザーが選択すると、その郵便番号の任意のチューターが表示されます.4番目と最後のユーザーが郵便番号と主題を入力すると、その主題とその郵便番号を教えるすべてのチューターが表示されます.

そのようにするのは簡単ですが、3 番目と 4 番目を少し複雑にするために、ユーザーが入力した郵便番号から半径 40 マイル以内にあるすべての郵便番号を選択します (すべての郵便番号と緯度と経度の表を使用)。 )。その半径内のすべての郵便番号の検索が機能しています。

私の質問はこれ です 配列を使用してそのデータベースにクエリを実行する方法は? その半径内のすべての郵便番号は配列に入れられているため、SELECT ステートメントを使用して "SELECT * FROM wp_testimonials WHERE postcode = '".$THIS IS MY ARRAY??"' AND find_in_set( '".$_REQUEST ['件名']."'、件名)"

結果ページのコード

<?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

4 に答える 4

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>

家庭教師データベーステーブル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');
于 2013-03-22T23:46:18.677 に答える
0

SELECT クエリで配列を使用できる場合は申し訳ありませんが、配列を使用してデータベースに直接クエリを実行できるとは思いませんが、郵便番号配列をループして、各郵便番号でデータベースにクエリを実行できます。

$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>';

→それはあなたが探しているものですか?

于 2013-03-22T00:13:25.460 に答える
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');
于 2013-03-22T00:21:43.390 に答える