Jump to content

Site Won't Submit Multiple Variables


BobJohnson

Recommended Posts

    I have a webpage that I am working on that is now in construction mode. The url is: https://localbizseek.com/lbs/index6  The problem is that I want to it to be able to search 2 at the same time in the phpmyadmin database table which is named "places".  I also want to be able to get to search all 9 cities for that area.  There are a total of 36,000+ cities in the database.  However, I want it to be able to search just 2 or 9 specific cities of those cities.  Each city has a city_id which is an integer assigned to it in the database  Right now it will search only 1 city at a time or it will search every city in the database if I assign the search variable as "" or "0".  I don't know what to do on this page to solve it and on the related processing page.  Here is the code on the webpage:
   
              

        <form id="main-search-form" method="GET" action="<?= $baseurl; ?>/_searchresults.php" role="search">
         
        
        <select id="query-input" name="city_id" style="width:28.8%" style="height:69px" required>
                        
        <option value="">Select Area</option>
             
        <option value="3;1">Ches & VB</option>
        <option value="3">Chesapeake , VA</option>
        <option value="9">Hampton , VA</option> 
        <option value="10">Newport News , VA</option>   
        <option value="2">Norfolk , VA</option>   
        <option value="12">Poquoson , VA</option> 
        <option value="4">Portsmouth , VA</option>    
        <option value="5">Suffolk , VA</option>    
        <option value="1">Virginia Beach , VA</option> 
        <option value="11">Williamsburg , VA</option>
        <option value="0">All Active US Cities</option>
        </select>
        </form>

    You will notice that I have tried "3;1" up under the Ches & VB Select Option but that doesn't work because it will not work that way.  I can have it as "3 1" but then it just displays 1 which is VB's information.  I've tried everything possible and it won't search both variables.  It only will search one.
   
    So I'm thinking I need to do something at both ends on the code.  Here is the other end of the code which is the results processing page.  Note that there is also a third page of code which is the template page which I will add next:
   
             

      <form id="main-search-form" method="GET" action="<?= $baseurl; ?>/_searchresults.php" role="search">
         
        
          <select id="query-input" name="city_id" style="width:28.8%" style="height:69px" required>
                        
              <option value="">Select Area</option>
             
              <option value="3,1">Ches & VB</option>
              <option value="3">Chesapeake , VA</option>
        <option value="9">Hampton , VA</option> 
        <option value="10">Newport News , VA</option>   
        <option value="2">Norfolk , VA</option>   
        <option value="12">Poquoson , VA</option> 
        <option value="4">Portsmouth , VA</option>    
                    <option value="5">Suffolk , VA</option>    
                    <option value="1">Virginia Beach , VA</option> 
        <option value="11">Williamsburg , VA</option>
                    <option value="0">All Active US Cities</option>
   
      
           
        </select>

    Here is the final page of code which I'm not sure if this one needs changing but just in case here it is:
   

    <!DOCTYPE html>
    <!--[if IE 9]><html class="lt-ie10" lang="<?= $html_lang; ?>"> <![endif]-->
    <html class="no-js" lang="<?= $html_lang; ?>">
    <head>
    <title><?= $txt_html_title; ?> - <?= $site_name; ?></title>
    <meta name="description" content="<?= $txt_meta_desc; ?>" />
    <meta name="robots" content="noindex">
    <?php require_once('_html_head.php'); ?>
    </head>
    <body class="tpl-searchresults">
    <?php require_once('_header.php'); ?>
   
     <h1><?= $txt_main_title; ?></h1>
   
     <div class="full-block">
      <div class="content-col">
       <div class="list-items">
        <?php
        /*
        --------------------------------------------------
        BEGIN SHOW LIST
        --------------------------------------------------
        */
        if($total_rows > 0) {
         $count = ($page - 1) * $limit;
         $results_arr = array();
   
         foreach($list_items as $k => $v) {
          $count++;
          $place_id         = $v['place_id'];
          $place_name       = $v['place_name'];
          $place_slug       = $v['place_slug'];
          $address          = $v['address'];
          $cross_street     = $v['cross_street'];
          $place_city_name  = $v['place_city_name'];
          $place_city_slug  = $v['place_city_slug'];
          $place_state_abbr = $v['place_state_abbr'];
          $postal_code      = $v['postal_code'];
          $area_code        = $v['area_code'];
          $phone            = $v['phone'];
                                                    $phone = preg_replace("/[^0-9]/", "", $phone);
                                                    $phone = substr($phone, 0, 3) . '-' . substr($phone, 3);
          $lat              = $v['lat'];
          $lng              = $v['lng'];
          $cat_icon         = $v['cat_icon'];
          $photo_url        = $v['photo_url'];
          $rating           = $v['rating'];
          $description      = $v['description'];
   
          $results_arr[] = array(
           'ad_id'    => $place_id,
           'ad_lat'   => $lat,
           'ad_lng'   => $lng,
           'ad_title' => $place_name,
           'count'    => $count,
           'cat_icon' => $cat_icon);
          $places_names_arr[] = $place_name;
          ?>
          <div class="item" data-ad_id="<?= $place_id; ?>">
           <div class="item-pic" id="<?= $place_id; ?>">
            <img src="<?= $photo_url; ?>" />
           </div><!-- .item-pic -->
   
           <div class="item-description">
            <div class="item-title-row">
             <div class="item-counter"><div class="item-counter-inner"><?= $count; ?></div></div>
   
             <h2><a href="<?= $baseurl; ?>/<?= $place_city_slug; ?>/place/<?= $place_id; ?>/<?= $place_slug; ?>" title="<?= $place_name; ?>"><?= $place_name; ?></a></h2>
            </div>
            <div class="item-ratings-wrapper">
             <div class="item-rating" data-rating="<?= $rating; ?>">
              <!-- raty plugin placeholder -->
             </div>
             <div class="item-ratings-count">
              <?php // echo $count_rating; ?> <?php // echo ($count_rating == 1 ? 'review' : 'reviews'); ?>
             </div>
             <div class="clear"></div>
            </div><!-- .item-ratings-wrapper -->
            <div class="item-info">
             <div class="item-addr">
              <strong>
               <?= (!empty($address)) ? $address : ''; ?>
              </strong>
              <?= (!empty($cross_street)) ? "($cross_street)" : ''; ?>
              <br>
              <strong>
               <?= (!empty($place_city_name))  ? "$place_city_name," : ''; ?>
               <?= (!empty($place_state_abbr)) ? " $place_state_abbr " : ''; ?>
               <?= (!empty($postal_code))      ? $postal_code : ''; ?>
              </strong>
             </div>
   
             <div class="item-phone">
              <?= (!empty($phone)) ? '<i class="fa fa-phone-square"></i>' : ''; ?>
              <?= (!empty($area_code)) ? $area_code : ''; ?>
              <?= (!empty($phone)) ? $phone : ''; ?>
             </div>
            </div><!-- .item-info -->
   
            <?php
            echo (!empty($tip_text)) ? $tip_text : '';
            ?>
           </div><!-- .item-description -->
   
           <div class="clear"></div>
          </div><!-- .item  -->
          <?php
         } //  end foreach($response as $k => $v)
        } // end if($total_rows > 0)
       else {
        // else no results found
        ?>
        <div class="empty-cat-template">
         <p><?= $txt_empty_results; ?></p>
        </div>
        <?php
       }
       ?>
       </div><!-- .list-items -->
   
       <?php
       /*
       --------------------------------------------------
       BEGIN PAGER
       --------------------------------------------------
       */
       ?>
       <div id="pager">
        <ul class="pagination">
         <?php
         if(!empty($pager) && $pager->getTotalPages() > 1) {
          $curPage = $page;
   
          $startPage = ($curPage < 5)? 1 : $curPage - 4;
          $endPage = 8 + $startPage;
          $endPage = ($pager->getTotalPages() < $endPage) ? $pager->getTotalPages() : $endPage;
          $diff = $startPage - $endPage + 8;
          $startPage -= ($startPage - $diff > 0) ? $diff : 0;
   
          $startPage = ($startPage == 1) ? 2 : $startPage;
          $endPage = ($endPage == $pager->getTotalPages()) ? $endPage - 1 : $endPage;
   
          if($total_rows > 0) {
           $page_url = "$baseurl/_searchresults.php?city_id=$query_city_id&query=$query_query&page=";
   
           if ($curPage > 1) {
            ?>
            <li><a href="<?= $page_url; ?>1">Page 1</a></li>
            <?php
           }
   
           if ($curPage > 6) {
            ?>
            <li><span>...</span></li>
            <?php
           }
   
           if ($curPage == 1) {
            ?>
            <li class="active"><span>Page 1</span></li>
            <?php
           }
   
           for($i = $startPage; $i <= $endPage; $i++) {
            if($i == $page) {
             ?>
             <li class="active"><span><?= $i; ?></span></li>
             <?php
            }
            else {
             ?>
             <li><a href="<?php echo $page_url, $i; ?>"><?= $i; ?></a></li>
             <?php
            }
           }
   
           if($curPage + 5 < $pager->getTotalPages()) {
            ?>
            <li><span>...</span></li>
            <?php
           }
   
           if($pager->getTotalPages() > 5) {
            $last_page_txt = "Last Page";
           }
   
           $last_page_txt = ($pager->getTotalPages() > 5) ? "Last Page" : $pager->getTotalPages();
   
           if($curPage == $pager->getTotalPages()) {
            ?>
            <li class="active"><span><?= $last_page_txt; ?></span></li>
            <?php
           }
           else {
            ?>
            <li><a href="<?php echo $page_url, $pager->getTotalPages(); ?>"><?= $last_page_txt; ?></a></li>
            <?php
           }
          } //  end if($total_rows > 0)
         } //  end if(isset($pager) && $pager->getTotalPages() > 1)
   
         if(isset($pager) && $pager->getTotalPages() == 1) {
          ?>
   
          <?php
         }
         ?>
        </ul>
       </div><!-- #pager -->
      </div><!-- .content-col -->
      
   
      <div class="sidebar"><div class="clear"></div>
       <?php
       if($total_rows > 0) {
        ?>
          <div class="clear"></div>
        <div class="map-wrapper" id="sticker">
         <div id="map-canvas" style="width:100%; height:100%"></div>
        </div>
        <?php
       }
       ?>
      </div>
       <div class="clear"></div>
      
      
      <!-- #sidebar -->
   
      <div class="clear"></div>
     </div><!-- .content-full -->
   
    <?php require_once('_footer.php'); ?>
    <script type="text/javascript" src="https://maps.googleapis.com/maps/api/js?key=<?= $google_key; ?>"></script>
   
    <script type="text/javascript">
    // place markers
    var results_obj = <?php echo json_encode($results_arr); ?>;
    var infowindow;
    var map;
   
    function initialize() {
     markers = {};
     infoboxcontents = {};
   
     // set map options
     var mapOptions = {
      zoom: 1
     };
   
     // instantiate map
     var map = new google.maps.Map(document.getElementById('map-canvas'), mapOptions);
     var bounds = new google.maps.LatLngBounds();
     var infowindow = new google.maps.InfoWindow();
   
     // $results_arr[] = array("ad_id" => $place_id, "ad_lat" => $ad_lat, "ad_lng" => $ad_lng, "ad_title" => $ad_title, "count" => $count);
   
     // set markers
     for (var k in results_obj) {
      var p = results_obj[k];
      var latlng = new google.maps.LatLng(p.ad_lat, p.ad_lng);
      bounds.extend(latlng);
   
      var marker_icon = '<?= $baseurl; ?>/imgs/marker1.png';
   
      // place markers
      var marker = new google.maps.Marker({
       position: latlng,
       map: map,
       animation: google.maps.Animation.DROP,
       title: p.ad_title,
       //icon: marker_icon
      });
   
      markers[p.ad_id] = marker;
      infoboxcontents[p.ad_id] = p.ad_title;
   
      // click event on markers to show infowindow
      google.maps.event.addListener(marker, 'click', function() {
       infowindow.setContent(this.title);
       infowindow.open(map, this);
      });
     } // end for (var k in results_obj)
   
     map.fitBounds(bounds);
   
     $(".list-items .item").mouseover(function() {
      marker = markers[this.getAttribute("data-ad_id")];
      // mycontent = infoboxcontents[this.getAttribute("data-ad_id")];
   
      mycontent =  '<div class="scrollFix">' + infoboxcontents[this.getAttribute("data-ad_id")] + '</div>';
      // console.log(mycontent);
   
      infowindow.setContent(mycontent);
      // infowindow.setOptions({maxWidth:300});
      infowindow.open(map, marker);
      marker.setZIndex(10000);
     }); // end mouseover
    } //  end initialize()
   
    google.maps.event.addDomListener(window, 'load', initialize);
    </script>
   
    <script type="text/javascript">
    $.fn.raty.defaults.path = '<?= $baseurl; ?>/templates/lib/raty/images';
    $('.item-rating').raty({
     readOnly: true,
     score: function(){
      return this.getAttribute('data-rating');
     }
    });
    </script>
    <script>
    $(document).ready(function(){
     $("#sidebar").sticky({topSpacing:0});
    });
    </script>
   
    <script>
      $(document).ready(function(){
        $("#sticker").sticky({topSpacing: 24});
      });
    </script>
    <script type="text/javascript">
    function getUrlVars() {
        var vars = [], hash;
        var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
        for(var i = 0; i < hashes.length; i++) {
            hash = hashes.split('=');
            vars.push(hash[0]);
            vars[hash[0]] = hash[1];
        }
        return vars;
    }
   
    $(document).ready(function() {
     var loc = '<?= e($_GET['loc']); ?>';
     var query = '<?= e($_GET['query']); ?>';
     if(loc !== '') {
      $("#city-input").val(loc);
     }
     if(query !== '') {
      $("#query-input").val(query);
     }
    });
   
    </script>
    </body>
    </html>

 

Edited by requinix
please use the Code <> button when posting code.
Link to comment
Share on other sites

5 minutes ago, requinix said:

using 3;1 or 3,1 could work if your code knew that it had to handle those. But I don't see where that code is...

I accidentally put the wrong second page up.  Here is all of it the rightway:

    I have a webpage that I am working on that is now in construction mode. The url is:
https://localbizseek.com/lbs/index6  The problem is that I want to it to be able to search
2 at the same time in the phpmyadmin database table which is named "places".  I also want
to be able to get to search all 9 cities for that area.  There are a total of 36,000+
cities in the database.  However, I want it to be able to search just 2 or 9 specific
cities of those cities.  Each city has a city_id which is an integer assigned to it in the
database  Right now it will search only 1 city at a time or it will search every city in
the database if I assign the search variable as "" or "0".  I don't know what to do on
this page to solve it and on the related processing page.  Here is the code on the
webpage:
    
                                 

        <form id="main-search-form" method="GET" action="<?= $baseurl; ?
>/_searchresults.php" role="search">
                
            
        <select id="query-input" name="city_id" style="width:28.8%" style="height:69px"
required>
                                        
        <option value="">Select Area</option>
                    
        <option value="3;1">Ches & VB</option>
        <option value="3">Chesapeake , VA</option>
        <option value="9">Hampton , VA</option>    
        <option value="10">Newport News , VA</option>            
        <option value="2">Norfolk , VA</option>            
        <option value="12">Poquoson , VA</option>    
        <option value="4">Portsmouth , VA</option>                
        <option value="5">Suffolk , VA</option>                
        <option value="1">Virginia Beach , VA</option>    
        <option value="11">Williamsburg , VA</option>
        <option value="0">All Active US Cities</option>
        </select>
        </form>


    
    
    You will notice that I have tried "3;1" up under the Ches & VB Select Option but that
doesn't work because it will not work that way.  I can have it as "3 1" but then it just
displays 1 which is VB's information.  I've tried everything possible and it won't search
both variables.  It only will search one.
    
    So I'm thinking I need to do something at both ends on the code.  Here is the other
end of the code which is the results processing page.  

<?php
require_once(__DIR__ . '/inc/config.php');
?>
<?php
$total_rows = 0;
$response = array();

$query_city_id = (!empty($_GET['city_id'])) ? $_GET['city_id'] : 0;
$query_query   = (!
empty($_GET['query']))   ? $_GET['query']   : '';  
$page          = (!empty($_GET
['page']))    ? $_GET['page']    : 1;

// check vars
if(!is_numeric($query_city_id)) {
    
die('Wrong city id');
}
$query_city_id = (int)$query_city_id;

// city details
$query_city_name
 = '';
$query_state_abbr = '';
if(!empty($query_city_id)) {
    $query = "SELECT
city_name, state FROM cities WHERE city_id = :query_city_id";
    $stmt = $conn->prepare
($query);
    $stmt->bindValue(':query_city_id', $query_city_id);
    $stmt->execute();
    
$row = $stmt->fetch(PDO::FETCH_ASSOC);
    $query_city_name = $row['city_name'];
    
$query_state_abbr = $row['state'];
}

// paging vars
$limit = $items_per_page;
if($page > 1) {
    
$offset = ($page-1) * $limit + 1;
}
else {
    $offset = 1;
}

// get page
if($page == 1) {
    
$pag = '';
}
else {
    $pag = "- $txt_page $page";
}

// count total rows
if(!empty
($query_city_id) && !empty($query_query)) {
    $query = "SELECT COUNT(*) AS total_rows
        
FROM places
        WHERE city_id = :city_id AND status != 'trashed' AND paid = 1
        
    AND MATCH(place_name, description) AGAINST(:query) ";

    $stmt = $conn->prepare
($query);
    $stmt->bindValue(':city_id', $query_city_id);
    $stmt->bindValue(':query',
$query_query);
    $stmt->execute();
    $row = $stmt->fetch(PDO::FETCH_ASSOC);
    
$total_rows = $row['total_rows'];
}
else if (empty($query_city_id) && !empty($query_query))
{
    $query = "SELECT COUNT(*) AS total_rows
        FROM places
        WHERE
status != 'trashed' AND paid = 1
        AND MATCH(place_name, description)
AGAINST(:query)";

    $stmt = $conn->prepare($query);
    $stmt->bindValue(':query',
$query_query);
    $stmt->execute();
    $row = $stmt->fetch(PDO::FETCH_ASSOC);
    
$total_rows = $row['total_rows'];
}
else if (!empty($query_city_id) && empty($query_query))
{
    $query = "SELECT COUNT(*) AS total_rows
        FROM places
        WHERE
status != 'trashed' AND paid = 1 AND city_id = :city_id";

    $stmt = $conn->prepare
($query);
    $stmt->bindValue(':city_id', $query_city_id);
    $stmt->execute();
    
$row = $stmt->fetch(PDO::FETCH_ASSOC);
    $total_rows = $row['total_rows'];
}
else {
    
$total_rows = 0;
}

$pager = new DirectoryApp\PageIterator($limit, $total_rows, $page);
$start
= $pager->getStartRow();

// initialize empty city and query check
$empty_city_and_query =
false;

/*--------------------------------------------------
LIST ITEMS LOGIC
--------------------------------------------------*/
if(!empty($query_city_id) && !empty
($query_query)) {
    $query = "SELECT p.place_id, p.place_name, p.address,
p.cross_street,
                p.postal_code, p.phone, p.area_code, p.lat, p.lng,
p.state_id, p.description,
                c.city_name, c.slug, c.state,
ph.filename, ph.dir,
                rev_table.avg_rating
                
FROM places p
                LEFT JOIN cities c ON p.city_id = c.city_id
        
        LEFT JOIN photos ph ON p.place_id = ph.place_id
                
LEFT JOIN (
                    SELECT *,
                    
    AVG(rev.rating) AS avg_rating
                        FROM
reviews rev

                    ) rev_table ON p.place_id =
rev_table.place_id
                WHERE p.city_id = :city_id AND p.status !=
'trashed' AND paid = 1
                    AND MATCH(place_name, description)
AGAINST(:query)

                LIMIT :start, :limit";
    $stmt = $conn->prepare
($query);
    $stmt->bindValue(':city_id', $query_city_id);
    $stmt->bindValue(':query',
$query_query);
    $stmt->bindValue(':start', $start);
    $stmt->bindValue(':limit',
$limit);
}

else if(empty($query_city_id) && !empty($query_query)) {
    $query = "SELECT
p.place_id, p.place_name, p.address, p.cross_street,
                
p.postal_code, p.phone, p.area_code, p.lat, p.lng, p.state_id, p.description,
            
    c.city_name, c.slug, c.state, ph.filename, ph.dir,
                
rev_table.avg_rating
                FROM places p
                
LEFT JOIN cities c ON p.city_id = c.city_id
                LEFT JOIN photos
ph ON p.place_id = ph.place_id
                LEFT JOIN (
                
    SELECT *,
                        AVG(rev.rating) AS
avg_rating
                        FROM reviews rev
            
        ) rev_table ON p.place_id = rev_table.place_id
                
WHERE p.status != 'trashed' AND paid = 1
                    AND MATCH
(place_name, description) AGAINST(:query)

                LIMIT :start,
:limit";
    $stmt = $conn->prepare($query);
    $stmt->bindValue(':query', $query_query);
    
$stmt->bindValue(':start', $start);
    $stmt->bindValue(':limit', $limit);
}

else if(!
empty($query_city_id) && empty($query_query)) {
    $query = "SELECT p.place_id, p.place_name,
p.address, p.cross_street,
                p.postal_code, p.phone,
p.area_code, p.lat, p.lng, p.state_id, p.description,
                
c.city_name, c.slug, c.state, ph.filename, ph.dir,
                
rev_table.avg_rating
                FROM places p
                
LEFT JOIN cities c ON p.city_id = c.city_id
                LEFT JOIN photos
ph ON p.place_id = ph.place_id
                LEFT JOIN (
                
    SELECT *,
                        AVG(rev.rating) AS
avg_rating
                        FROM reviews rev

            
        ) rev_table ON p.place_id = rev_table.place_id
                
WHERE p.city_id = :city_id AND p.status != 'trashed' AND paid = 1

                
LIMIT :start, :limit";
    $stmt = $conn->prepare($query);
    $stmt->bindValue(':city_id',
$query_city_id);
    $stmt->bindValue(':start', $start);
    $stmt->bindValue(':limit',
$limit);
}

else{ // both $query_loc and $query_query empty
    $empty_city_and_query =
true;
}

// now execute query
$stmt->execute();

// build results array
if($total_rows > 0) {
    
while($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
        $place_id         = $row
['place_id'];
        $place_name       = $row['place_name'];
        $address          
= $row['address'];
        $cross_street     = $row['cross_street'];
        
$place_city_name  = $row['city_name'];
        $place_city_slug  = $row['slug'];
        
$place_state_id   = $row['state_id'];
        $place_state_abbr = $row['state'];
        
$postal_code      = $row['postal_code'];
        $area_code        = $row
['area_code'];
        $phone            = $row['phone'];
        $lat              
= $row['lat'];
        $lng              = $row['lng'];
        $rating          
= $row['avg_rating'];
        $description      = $row['description'];

        //
short description
        $description = get_snippet($description, 20);

        //
cat icon (just use blank img for now)
        $cat_icon = $baseurl . '/imgs/blank.png';

    
    // thumb
        if(!empty($row['filename'])) {
            $photo_url
= $baseurl . '/place_pic_thumb/' . $row['dir'] . '/' . $row['filename'];
        }
    
    else {
            $photo_url = $cat_icon;
        }

        // clean
place name
        $endash = html_entity_decode('–', ENT_COMPAT, 'UTF-8');
        
$place_name = str_replace($endash, "-", $place_name);

        $list_items[] = array(
        
    'place_id'         => $place_id,
            'place_name'       => e
($place_name),
            'place_slug'       => to_slug($place_name),
            
'address'          => e($address),
            'cross_street'     => e
($cross_street),
            'place_city_name'  => $place_city_name,
            
'place_city_slug'  => $place_city_slug,
            'place_state_abbr' =>
$place_state_abbr,
            'postal_code'      => e($postal_code),
            
'area_code'        => e($area_code),
            'phone'            => e($phone),
    
        'lat'              => $lat,
            'lng'              =>
$lng,
            'cat_icon'         => $cat_icon,
            
'photo_url'        => $photo_url,
            'rating'           => $rating,
        
    'description'      => $description
        );
    }
}

$location = '';
if(!
empty($query_city_name) && !empty($query_state_abbr)) {
    $location = "$query_city_name,
$query_state_abbr";
}

// translations
if(empty($location)) {
    $txt_html_title    =
$txt_html_title_no_loc;
    $txt_meta_desc     = $txt_meta_desc_no_loc;
    $txt_main_title    
= $txt_main_title_no_loc;

    $txt_html_title    = str_replace('%search_term%', e
($query_query), $txt_html_title);
    $txt_meta_desc     = str_replace('%search_term%',
e($query_query), $txt_meta_desc);
    $txt_main_title    = str_replace('%search_term%',
e($query_query), $txt_main_title);
    $txt_empty_results = str_replace('%search_term%',
e($query_query), $txt_empty_results);
}
else {
    $txt_html_title    = str_replace
('%search_term%', e($query_query), $txt_html_title);
    $txt_html_title    = str_replace
('%location%'   , $location      , $txt_html_title);
    $txt_meta_desc     = str_replace
('%search_term%', e($query_query), $txt_meta_desc);
    $txt_meta_desc     = str_replace
('%location%'   , $location      , $txt_meta_desc);
    $txt_main_title    = str_replace
('%search_term%', e($query_query), $txt_main_title);
    $txt_main_title    = str_replace
('%location%'   , $location      , $txt_main_title);
    $txt_empty_results = str_replace
('%search_term%', e($query_query), $txt_empty_results);
}

// template file
require_once
(__DIR__ . '/templates/tpl_searchresults.php');


    
    Here is the final page of code which I'm not sure if this one needs changing but just
in case here it is:
    
    <!DOCTYPE html>
    <!--[if IE 9]><html class="lt-ie10" lang="<?= $html_lang; ?>"> <![endif]-->
    <html class="no-js" lang="<?= $html_lang; ?>">
    <head>
    <title><?= $txt_html_title; ?> - <?= $site_name; ?></title>
    <meta name="description" content="<?= $txt_meta_desc; ?>" />
    <meta name="robots" content="noindex">
    <?php require_once('_html_head.php'); ?>
    </head>
    <body class="tpl-searchresults">
    <?php require_once('_header.php'); ?>
    
        <h1><?= $txt_main_title; ?></h1>
    
        <div class="full-block">
            <div class="content-col">
                <div class="list-items">
                    <?php
                    /*
                    --------------------------------------------------
                    BEGIN SHOW LIST
                    --------------------------------------------------
                    */
                    if($total_rows > 0) {
                        $count = ($page - 1) * $limit;
                        $results_arr = array();
    
                        foreach($list_items as $k => $v) {
                            $count++;
                            $place_id         = $v['place_id'];
                            $place_name       = $v['place_name'];
                            $place_slug       = $v['place_slug'];
                            $address          = $v['address'];
                            $cross_street     = $v['cross_street'];
                            $place_city_name  = $v['place_city_name'];
                            $place_city_slug  = $v['place_city_slug'];
                            $place_state_abbr = $v
['place_state_abbr'];
                            $postal_code      = $v['postal_code'];
                            $area_code        = $v['area_code'];
                            $phone            = $v['phone'];
                                                    $phone = preg_replace("/[^0-9]/", "",
$phone);
                                                    $phone = substr($phone, 0, 3) . '-' .
substr($phone, 3);
                            $lat              = $v['lat'];
                            $lng              = $v['lng'];
                            $cat_icon         = $v['cat_icon'];
                            $photo_url        = $v['photo_url'];
                            $rating           = $v['rating'];
                            $description      = $v['description'];
    
                            $results_arr[] = array(
                                'ad_id'    => $place_id,
                                'ad_lat'   => $lat,
                                'ad_lng'   => $lng,
                                'ad_title' => $place_name,
                                'count'    => $count,
                                'cat_icon' => $cat_icon);
                            $places_names_arr[] = $place_name;
                            ?>
                            <div class="item" data-ad_id="<?=
$place_id; ?>">
                                <div class="item-pic" id="<?=
$place_id; ?>">
                                    <img src="<?= $photo_url;
?>" />
                                </div><!-- .item-pic -->
    
                                <div class="item-description">
                                    <div class="item-title-
row">
                                        <div class="item-
counter"><div class="item-counter-inner"><?= $count; ?></div></div>
    
                                        <h2><a href="<?=
$baseurl; ?>/<?= $place_city_slug; ?>/place/<?= $place_id; ?>/<?= $place_slug; ?>"
title="<?= $place_name; ?>"><?= $place_name; ?></a></h2>
                                    </div>
                                    <div class="item-ratings-
wrapper">
                                        <div class="item-
rating" data-rating="<?= $rating; ?>">
                                            <!-- raty
plugin placeholder -->
                                        </div>
                                        <div class="item-
ratings-count">
                                            <?php //
echo $count_rating; ?> <?php // echo ($count_rating == 1 ? 'review' : 'reviews'); ?>
                                        </div>
                                        <div
class="clear"></div>
                                    </div><!-- .item-ratings-
wrapper -->
                                    <div class="item-info">
                                        <div class="item-
addr">
                                            <strong>
                                                
<?= (!empty($address)) ? $address : ''; ?>
                                            </strong>
                                            <?= (!
empty($cross_street)) ? "($cross_street)" : ''; ?>
                                            <br>
                                            <strong>
                                                
<?= (!empty($place_city_name))  ? "$place_city_name," : ''; ?>
                                                
<?= (!empty($place_state_abbr)) ? " $place_state_abbr " : ''; ?>
                                                
<?= (!empty($postal_code))      ? $postal_code : ''; ?>
                                            </strong>
                                        </div>
    
                                        <div class="item-
phone">
                                            <?= (!
empty($phone)) ? '<i class="fa fa-phone-square"></i>' : ''; ?>
                                            <?= (!
empty($area_code)) ? $area_code : ''; ?>
                                            <?= (!
empty($phone)) ? $phone : ''; ?>
                                        </div>
                                    </div><!-- .item-info -->
    
                                    <?php
                                    echo (!empty($tip_text)) ?
$tip_text : '';
                                    ?>
                                </div><!-- .item-description -->
    
                                <div class="clear"></div>
                            </div><!-- .item  -->
                            <?php
                        } //  end foreach($response as $k => $v)
                    } // end if($total_rows > 0)
                else {
                    // else no results found
                    ?>
                    <div class="empty-cat-template">
                        <p><?= $txt_empty_results; ?></p>
                    </div>
                    <?php
                }
                ?>
                </div><!-- .list-items -->
    
                <?php
                /*
                --------------------------------------------------
                BEGIN PAGER
                --------------------------------------------------
                */
                ?>
                <div id="pager">
                    <ul class="pagination">
                        <?php
                        if(!empty($pager) && $pager->getTotalPages() > 1)
{
                            $curPage = $page;
    
                            $startPage = ($curPage < 5)? 1 : $curPage
- 4;
                            $endPage = 8 + $startPage;
                            $endPage = ($pager->getTotalPages() <
$endPage) ? $pager->getTotalPages() : $endPage;
                            $diff = $startPage - $endPage + 8;
                            $startPage -= ($startPage - $diff > 0) ?
$diff : 0;
    
                            $startPage = ($startPage == 1) ? 2 :
$startPage;
                            $endPage = ($endPage == $pager-
>getTotalPages()) ? $endPage - 1 : $endPage;
    
                            if($total_rows > 0) {
                                $page_url =
"$baseurl/_searchresults.php?city_id=$query_city_id&query=$query_query&page=";
    
                                if ($curPage > 1) {
                                    ?>
                                    <li><a href="<?=
$page_url; ?>1">Page 1</a></li>
                                    <?php
                                }
    
                                if ($curPage > 6) {
                                    ?>
                                    <li><span>...</span></li>
                                    <?php
                                }
    
                                if ($curPage == 1) {
                                    ?>
                                    <li
class="active"><span>Page 1</span></li>
                                    <?php
                                }
    
                                for($i = $startPage; $i <=
$endPage; $i++) {
                                    if($i == $page) {
                                        ?>
                                        <li
class="active"><span><?= $i; ?></span></li>
                                        <?php
                                    }
                                    else {
                                        ?>
                                        <li><a href="<?php
echo $page_url, $i; ?>"><?= $i; ?></a></li>
                                        <?php
                                    }
                                }
    
                                if($curPage + 5 < $pager-
>getTotalPages()) {
                                    ?>
                                    <li><span>...</span></li>
                                    <?php
                                }
    
                                if($pager->getTotalPages() > 5) {
                                    $last_page_txt = "Last
Page";
                                }
    
                                $last_page_txt = ($pager-
>getTotalPages() > 5) ? "Last Page" : $pager->getTotalPages();
    
                                if($curPage == $pager-
>getTotalPages()) {
                                    ?>
                                    <li
class="active"><span><?= $last_page_txt; ?></span></li>
                                    <?php
                                }
                                else {
                                    ?>
                                    <li><a href="<?php echo
$page_url, $pager->getTotalPages(); ?>"><?= $last_page_txt; ?></a></li>
                                    <?php
                                }
                            } //  end if($total_rows > 0)
                        } //  end if(isset($pager) && $pager-
>getTotalPages() > 1)
    
                        if(isset($pager) && $pager->getTotalPages() == 1)
{
                            ?>
    
                            <?php
                        }
                        ?>
                    </ul>
                </div><!-- #pager -->
            </div><!-- .content-col -->
            
    
            <div class="sidebar"><div class="clear"></div>
                <?php
                if($total_rows > 0) {
                    ?>
                            <div class="clear"></div>
                    <div class="map-wrapper" id="sticker">
                        <div id="map-canvas" style="width:100%;
height:100%"></div>
                    </div>
                    <?php
                }
                ?>
            </div>
                <div class="clear"></div>
            
            
            <!-- #sidebar -->
    
            <div class="clear"></div>
        </div><!-- .content-full -->
    
    <?php require_once('_footer.php'); ?>
    <script type="text/javascript" src="https://maps.googleapis.com/maps/api/js?key=<?=
$google_key; ?>"></script>
    
    <script type="text/javascript">
    // place markers
    var results_obj = <?php echo json_encode($results_arr); ?>;
    var infowindow;
    var map;
    
    function initialize() {
        markers = {};
        infoboxcontents = {};
    
        // set map options
        var mapOptions = {
            zoom: 1
        };
    
        // instantiate map
        var map = new google.maps.Map(document.getElementById('map-canvas'), mapOptions);
        var bounds = new google.maps.LatLngBounds();
        var infowindow = new google.maps.InfoWindow();
    
        // $results_arr[] = array("ad_id" => $place_id, "ad_lat" => $ad_lat, "ad_lng" =>
$ad_lng, "ad_title" => $ad_title, "count" => $count);
    
        // set markers
        for (var k in results_obj) {
            var p = results_obj[k];
            var latlng = new google.maps.LatLng(p.ad_lat, p.ad_lng);
            bounds.extend(latlng);
    
            var marker_icon = '<?= $baseurl; ?>/imgs/marker1.png';
    
            // place markers
            var marker = new google.maps.Marker({
                position: latlng,
                map: map,
                animation: google.maps.Animation.DROP,
                title: p.ad_title,
                //icon: marker_icon
            });
    
            markers[p.ad_id] = marker;
            infoboxcontents[p.ad_id] = p.ad_title;
    
            // click event on markers to show infowindow
            google.maps.event.addListener(marker, 'click', function() {
                infowindow.setContent(this.title);
                infowindow.open(map, this);
            });
        } // end for (var k in results_obj)
    
        map.fitBounds(bounds);
    
        $(".list-items .item").mouseover(function() {
            marker = markers[this.getAttribute("data-ad_id")];
            // mycontent = infoboxcontents[this.getAttribute("data-ad_id")];
    
            mycontent =  '<div class="scrollFix">' + infoboxcontents
[this.getAttribute("data-ad_id")] + '</div>';
            // console.log(mycontent);
    
            infowindow.setContent(mycontent);
            // infowindow.setOptions({maxWidth:300});
            infowindow.open(map, marker);
            marker.setZIndex(10000);
        }); // end mouseover
    } //  end initialize()
    
    google.maps.event.addDomListener(window, 'load', initialize);
    </script>
    
    <script type="text/javascript">
    $.fn.raty.defaults.path = '<?= $baseurl; ?>/templates/lib/raty/images';
    $('.item-rating').raty({
        readOnly: true,
        score: function(){
            return this.getAttribute('data-rating');
        }
    });
    </script>
    <script>
    $(document).ready(function(){
        $("#sidebar").sticky({topSpacing:0});
    });
    </script>
    
    <script>
      $(document).ready(function(){
        $("#sticker").sticky({topSpacing: 24});
      });
    </script>
    <script type="text/javascript">
    function getUrlVars() {
        var vars = [], hash;
        var hashes = window.location.href.slice(window.location.href.indexOf('?') +
1).split('&');
        for(var i = 0; i < hashes.length; i++) {
            hash = hashes.split('=');
            vars.push(hash[0]);
            vars[hash[0]] = hash[1];
        }
        return vars;
    }
    
    $(document).ready(function() {
        var loc = '<?= e($_GET['loc']); ?>';
        var query = '<?= e($_GET['query']); ?>';
        if(loc !== '') {
            $("#city-input").val(loc);
        }
        if(query !== '') {
            $("#query-input").val(query);
        }
    });
    
    </script>
    </body>
    </html>

 

Edited by requinix
Link to comment
Share on other sites

You probably didn't see that I edited your first, and now second, post: please use the Code <> button when posting code.

You can't simply change the value in your <option> and expect it to work. If you want to support multiple values then you have to have code that supports multiple values. And this

// check vars
if(!is_numeric($query_city_id)) {
    
die('Wrong city id');
}
$query_city_id = (int)$query_city_id;

and this

    $query = "SELECT
city_name, state FROM cities WHERE city_id = :query_city_id";
    $stmt = $conn->prepare
($query);
    $stmt->bindValue(':query_city_id', $query_city_id);

do not. Decide whether you want "3,1" or "3;1" or "3 1" or whatever, then adjust the code so it can support one or more city IDs at a time.

  • Thanks 1
Link to comment
Share on other sites

I just noticed what you did.  Thanks.  You put it in the right places.  I thought you meant you edited the code on those.  I will use the code <> button in any future posts.  I didn't realize I was doing it wrong.  This is my first time using this.

 

Link to comment
Share on other sites

Yes, my problem is that I don't know what to do to the code to get it to support multiple values.  I had tried  lot of things but cannot find much on that online.  My brother wrote the original code for me and I've been able to do a lot but this one I can't figure out.  He cannot help anymore so I'm quite stuck...

Link to comment
Share on other sites

I changed the code to be Select...Where id In (1,2,3...  but I think I'm missing something.   See code:

<?php
require_once(__DIR__ . '/inc/config.php');
?>
<?php
$total_rows = 0;
$response = array();

$query_city_id = (!empty($_GET['city_id'])) ? $_GET['city_id'] : 0;
$query_query   = (!empty($_GET['query']))   ? $_GET['query']   : '';  
$page          = (!empty($_GET['page']))    ? $_GET['page']    : 1;

// check vars
if(!is_numeric($query_city_id)) {
	die('Wrong city id');
}
$query_city_id = (int)$query_city_id;

// city details
$query_city_name  = '';
$query_state_abbr = '';
if(!empty($query_city_id)) {
    
    
    
	$query = "SELECT city_name, state FROM cities WHERE city_id In (1,2,3,4,5,9,10,11,12);
	$stmt = $conn->prepare($query);
	
	
	
	$stmt->bindValue(':query_city_id', $query_city_id);
	$stmt->execute();
	$row = $stmt->fetch(PDO::FETCH_ASSOC);
	$query_city_name = $row['city_name'];
	$query_state_abbr = $row['state'];
}

// paging vars
$limit = $items_per_page;
if($page > 1) {
	$offset = ($page-1) * $limit + 1;
}
else {
	$offset = 1;
}

// get page
if($page == 1) {
	$pag = '';
}
else {
	$pag = "- $txt_page $page";
}

// count total rows
if(!empty($query_city_id) && !empty($query_query)) {
	$query = "SELECT COUNT(*) AS total_rows
		FROM places
		WHERE city_id = :city_id AND status != 'trashed' AND paid = 1
			AND MATCH(place_name, description) AGAINST(:query) ";

	$stmt = $conn->prepare($query);
	$stmt->bindValue(':city_id', $query_city_id);
	$stmt->bindValue(':query', $query_query);
	$stmt->execute();
	$row = $stmt->fetch(PDO::FETCH_ASSOC);
	$total_rows = $row['total_rows'];
}
else if (empty($query_city_id) && !empty($query_query)) {
	$query = "SELECT COUNT(*) AS total_rows
		FROM places
		WHERE status != 'trashed' AND paid = 1
		AND MATCH(place_name, description) AGAINST(:query)";

	$stmt = $conn->prepare($query);
	$stmt->bindValue(':query', $query_query);
	$stmt->execute();
	$row = $stmt->fetch(PDO::FETCH_ASSOC);
	$total_rows = $row['total_rows'];
}
else if (!empty($query_city_id) && empty($query_query)) {
	$query = "SELECT COUNT(*) AS total_rows
		FROM places
		WHERE status != 'trashed' AND paid = 1 AND city_id = :city_id";

	$stmt = $conn->prepare($query);
	$stmt->bindValue(':city_id', $query_city_id);
	$stmt->execute();
	$row = $stmt->fetch(PDO::FETCH_ASSOC);
	$total_rows = $row['total_rows'];
}
else {
	$total_rows = 0;
}

$pager = new DirectoryApp\PageIterator($limit, $total_rows, $page);
$start = $pager->getStartRow();

// initialize empty city and query check
$empty_city_and_query = false;

/*--------------------------------------------------
LIST ITEMS LOGIC
--------------------------------------------------*/
if(!empty($query_city_id) && !empty($query_query)) {
	$query = "SELECT p.place_id, p.place_name, p.address, p.cross_street,
				p.postal_code, p.phone, p.area_code, p.lat, p.lng, p.state_id, p.description,
				c.city_name, c.slug, c.state, ph.filename, ph.dir,
				rev_table.avg_rating
				FROM places p
				LEFT JOIN cities c ON p.city_id = c.city_id
				LEFT JOIN photos ph ON p.place_id = ph.place_id
				LEFT JOIN (
					SELECT *,
						AVG(rev.rating) AS avg_rating
						FROM reviews rev

					) rev_table ON p.place_id = rev_table.place_id
				WHERE p.city_id = :city_id AND p.status != 'trashed' AND paid = 1
					AND MATCH(place_name, description) AGAINST(:query)

				LIMIT :start, :limit";
	$stmt = $conn->prepare($query);
	$stmt->bindValue(':city_id', $query_city_id);
	$stmt->bindValue(':query', $query_query);
	$stmt->bindValue(':start', $start);
	$stmt->bindValue(':limit', $limit);
}

else if(empty($query_city_id) && !empty($query_query)) {
	$query = "SELECT p.place_id, p.place_name, p.address, p.cross_street,
				p.postal_code, p.phone, p.area_code, p.lat, p.lng, p.state_id, p.description,
				c.city_name, c.slug, c.state, ph.filename, ph.dir,
				rev_table.avg_rating
				FROM places p
				LEFT JOIN cities c ON p.city_id = c.city_id
				LEFT JOIN photos ph ON p.place_id = ph.place_id
				LEFT JOIN (
					SELECT *,
						AVG(rev.rating) AS avg_rating
						FROM reviews rev
					) rev_table ON p.place_id = rev_table.place_id
				WHERE p.status != 'trashed' AND paid = 1
					AND MATCH(place_name, description) AGAINST(:query)

				LIMIT :start, :limit";
	$stmt = $conn->prepare($query);
	$stmt->bindValue(':query', $query_query);
	$stmt->bindValue(':start', $start);
	$stmt->bindValue(':limit', $limit);
}

else if(!empty($query_city_id) && empty($query_query)) {
	$query = "SELECT p.place_id, p.place_name, p.address, p.cross_street,
				p.postal_code, p.phone, p.area_code, p.lat, p.lng, p.state_id, p.description,
				c.city_name, c.slug, c.state, ph.filename, ph.dir,
				rev_table.avg_rating
				FROM places p
				LEFT JOIN cities c ON p.city_id = c.city_id
				LEFT JOIN photos ph ON p.place_id = ph.place_id
				LEFT JOIN (
					SELECT *,
						AVG(rev.rating) AS avg_rating
						FROM reviews rev

					) rev_table ON p.place_id = rev_table.place_id
				WHERE p.city_id = :city_id AND p.status != 'trashed' AND paid = 1

				LIMIT :start, :limit";
	$stmt = $conn->prepare($query);
	$stmt->bindValue(':city_id', $query_city_id);
	$stmt->bindValue(':start', $start);
	$stmt->bindValue(':limit', $limit);
}

else{ // both $query_loc and $query_query empty
	$empty_city_and_query = true;
}

// now execute query
$stmt->execute();

// build results array
if($total_rows > 0) {
	while($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
		$place_id         = $row['place_id'];
		$place_name       = $row['place_name'];
		$address          = $row['address'];
		$cross_street     = $row['cross_street'];
		$place_city_name  = $row['city_name'];
		$place_city_slug  = $row['slug'];
		$place_state_id   = $row['state_id'];
		$place_state_abbr = $row['state'];
		$postal_code      = $row['postal_code'];
		$area_code        = $row['area_code'];
		$phone            = $row['phone'];
		$lat              = $row['lat'];
		$lng              = $row['lng'];
		$rating           = $row['avg_rating'];
		$description      = $row['description'];

		// short description
		$description = get_snippet($description, 20);

		// cat icon (just use blank img for now)
		$cat_icon = $baseurl . '/imgs/blank.png';

		// thumb
		if(!empty($row['filename'])) {
			$photo_url = $baseurl . '/place_pic_thumb/' . $row['dir'] . '/' . $row['filename'];
		}
		else {
			$photo_url = $cat_icon;
		}

		// clean place name
		$endash = html_entity_decode('&#x2013;', ENT_COMPAT, 'UTF-8');
		$place_name = str_replace($endash, "-", $place_name);

		$list_items[] = array(
			'place_id'         => $place_id,
			'place_name'       => e($place_name),
			'place_slug'       => to_slug($place_name),
			'address'          => e($address),
			'cross_street'     => e($cross_street),
			'place_city_name'  => $place_city_name,
			'place_city_slug'  => $place_city_slug,
			'place_state_abbr' => $place_state_abbr,
			'postal_code'      => e($postal_code),
			'area_code'        => e($area_code),
			'phone'            => e($phone),
			'lat'              => $lat,
			'lng'              => $lng,
			'cat_icon'         => $cat_icon,
			'photo_url'        => $photo_url,
			'rating'           => $rating,
			'description'      => $description
		);
	}
}

$location = '';
if(!empty($query_city_name) && !empty($query_state_abbr)) {
	$location = "$query_city_name, $query_state_abbr";
}

// translations
if(empty($location)) {
	$txt_html_title    = $txt_html_title_no_loc;
	$txt_meta_desc     = $txt_meta_desc_no_loc;
	$txt_main_title    = $txt_main_title_no_loc;

	$txt_html_title    = str_replace('%search_term%', e($query_query), $txt_html_title);
	$txt_meta_desc     = str_replace('%search_term%', e($query_query), $txt_meta_desc);
	$txt_main_title    = str_replace('%search_term%', e($query_query), $txt_main_title);
	$txt_empty_results = str_replace('%search_term%', e($query_query), $txt_empty_results);
}
else {
	$txt_html_title    = str_replace('%search_term%', e($query_query), $txt_html_title);
	$txt_html_title    = str_replace('%location%'   , $location      , $txt_html_title);
	$txt_meta_desc     = str_replace('%search_term%', e($query_query), $txt_meta_desc);
	$txt_meta_desc     = str_replace('%location%'   , $location      , $txt_meta_desc);
	$txt_main_title    = str_replace('%search_term%', e($query_query), $txt_main_title);
	$txt_main_title    = str_replace('%location%'   , $location      , $txt_main_title);
	$txt_empty_results = str_replace('%search_term%', e($query_query), $txt_empty_results);
}

// template file
require_once(__DIR__ . '/templates/tpl_searchresults6.php');

 

Link to comment
Share on other sites

Here's a method for handling IN(...) with prepared statements.

<?php
if (isset($_GET['city_id'])) {
    if ($_GET['city_id'] != 0) {
        $ids = explode(';', $_GET['city_id']) ;        // split multiple ids
        $k = count($ids);
        $placeholders = array_fill(0, $k, '?');
        $placestr = join(',', $placeholders);
        $stmt = $conn->prepare("SELECT city_name, state FROM cities WHERE city_id IN ($placestr)");
        $stmt->execute($ids); 
    }
    else {
        // if you want all cities then a where clause is not needed
        $stmt = $conn->query("SELECT city_name, state FROM cities");        
    }
    // process the stmt results here
}
?>
<html>
<body>
    <form>
        <select id="query-input" name="city_id" style="width:28.8%" style="height:69px" required>
                                        
        <option value="">Select Area</option>
                    
        <option value="3;1">Ches & VB</option>
        <option value="3">Chesapeake , VA</option>
        <option value="9">Hampton , VA</option>    
        <option value="10">Newport News , VA</option>            
        <option value="2">Norfolk , VA</option>            
        <option value="12">Poquoson , VA</option>    
        <option value="4">Portsmouth , VA</option>                
        <option value="5">Suffolk , VA</option>                
        <option value="1">Virginia Beach , VA</option>    
        <option value="11">Williamsburg , VA</option>
        <option value="0">All Active US Cities</option>
        </select>
        <input type="submit" name="btnSub" value="Submit">
    </form></body>
</html>

 

Link to comment
Share on other sites

I put the code in but I think maybe I'm putting it in the wrong place.  But also the die code near the top where it states //Check Vars seems to be blocking the select option of 3,1.  But I took that out and it then worked but only pulled up 3's information which was for Ches.'s option in the select options.  Here's the changed code:

<?php
require_once(__DIR__ . '/inc/config.php');
?>
<?php
$total_rows = 0;
$response = array();

$query_city_id = (!empty($_GET['city_id'])) ? $_GET['city_id'] : 0;
$query_query   = (!empty($_GET['query']))   ? $_GET['query']   : '';  
$page          = (!empty($_GET['page']))    ? $_GET['page']    : 1;

// check vars
if(!is_numeric($query_city_id)) {
	die('Wrong city id');
}
$query_city_id = (int)$query_city_id;

// city details
$query_city_name  = '';
$query_state_abbr = '';
if (isset($_GET['city_id'])) {
    if ($_GET['city_id'] != 0) {
        $ids = explode(';', $_GET['city_id']) ;        // split multiple ids
        $k = count($ids);
        $placeholders = array_fill(0, $k, '?');
        $placestr = join(',', $placeholders);
        $stmt = $conn->prepare("SELECT city_name, state FROM cities WHERE city_id IN ($placestr)");
        $stmt->execute($ids); 
    }
    else {
        // if you want all cities then a where clause is not needed
        $stmt = $conn->query("SELECT city_name, state FROM cities");        
    }
    // process the stmt results here

	$stmt = $conn->prepare($query);
	$stmt->bindValue(':query_city_id', $query_city_id);
	$stmt->execute();
	$row = $stmt->fetch(PDO::FETCH_ASSOC);
	$query_city_name = $row['city_name'];
	$query_state_abbr = $row['state'];
}















// paging vars
$limit = $items_per_page;
if($page > 1) {
	$offset = ($page-1) * $limit + 1;
}
else {
	$offset = 1;
}

// get page
if($page == 1) {
	$pag = '';
}
else {
	$pag = "- $txt_page $page";
}

// count total rows
if(!empty($query_city_id) && !empty($query_query)) {
	$query = "SELECT COUNT(*) AS total_rows
		FROM places
		WHERE city_id = :city_id AND status != 'trashed' AND paid = 1
			AND MATCH(place_name, description) AGAINST(:query) ";

	$stmt = $conn->prepare($query);
	$stmt->bindValue(':city_id', $query_city_id);
	$stmt->bindValue(':query', $query_query);
	$stmt->execute();
	$row = $stmt->fetch(PDO::FETCH_ASSOC);
	$total_rows = $row['total_rows'];
}
else if (empty($query_city_id) && !empty($query_query)) {
	$query = "SELECT COUNT(*) AS total_rows
		FROM places
		WHERE status != 'trashed' AND paid = 1
		AND MATCH(place_name, description) AGAINST(:query)";

	$stmt = $conn->prepare($query);
	$stmt->bindValue(':query', $query_query);
	$stmt->execute();
	$row = $stmt->fetch(PDO::FETCH_ASSOC);
	$total_rows = $row['total_rows'];
}
else if (!empty($query_city_id) && empty($query_query)) {
	$query = "SELECT COUNT(*) AS total_rows
		FROM places
		WHERE status != 'trashed' AND paid = 1 AND city_id = :city_id";

	$stmt = $conn->prepare($query);
	$stmt->bindValue(':city_id', $query_city_id);
	$stmt->execute();
	$row = $stmt->fetch(PDO::FETCH_ASSOC);
	$total_rows = $row['total_rows'];
}
else {
	$total_rows = 0;
}

$pager = new DirectoryApp\PageIterator($limit, $total_rows, $page);
$start = $pager->getStartRow();

// initialize empty city and query check
$empty_city_and_query = false;

/*--------------------------------------------------
LIST ITEMS LOGIC
--------------------------------------------------*/
if(!empty($query_city_id) && !empty($query_query)) {
	$query = "SELECT p.place_id, p.place_name, p.address, p.cross_street,
				p.postal_code, p.phone, p.area_code, p.lat, p.lng, p.state_id, p.description,
				c.city_name, c.slug, c.state, ph.filename, ph.dir,
				rev_table.avg_rating
				FROM places p
				LEFT JOIN cities c ON p.city_id = c.city_id
				LEFT JOIN photos ph ON p.place_id = ph.place_id
				LEFT JOIN (
					SELECT *,
						AVG(rev.rating) AS avg_rating
						FROM reviews rev

					) rev_table ON p.place_id = rev_table.place_id
				WHERE p.city_id = :city_id AND p.status != 'trashed' AND paid = 1
					AND MATCH(place_name, description) AGAINST(:query)

				LIMIT :start, :limit";
	$stmt = $conn->prepare($query);
	$stmt->bindValue(':city_id', $query_city_id);
	$stmt->bindValue(':query', $query_query);
	$stmt->bindValue(':start', $start);
	$stmt->bindValue(':limit', $limit);
}

else if(empty($query_city_id) && !empty($query_query)) {
	$query = "SELECT p.place_id, p.place_name, p.address, p.cross_street,
				p.postal_code, p.phone, p.area_code, p.lat, p.lng, p.state_id, p.description,
				c.city_name, c.slug, c.state, ph.filename, ph.dir,
				rev_table.avg_rating
				FROM places p
				LEFT JOIN cities c ON p.city_id = c.city_id
				LEFT JOIN photos ph ON p.place_id = ph.place_id
				LEFT JOIN (
					SELECT *,
						AVG(rev.rating) AS avg_rating
						FROM reviews rev
					) rev_table ON p.place_id = rev_table.place_id
				WHERE p.status != 'trashed' AND paid = 1
					AND MATCH(place_name, description) AGAINST(:query)

				LIMIT :start, :limit";
	$stmt = $conn->prepare($query);
	$stmt->bindValue(':query', $query_query);
	$stmt->bindValue(':start', $start);
	$stmt->bindValue(':limit', $limit);
}

else if(!empty($query_city_id) && empty($query_query)) {
	$query = "SELECT p.place_id, p.place_name, p.address, p.cross_street,
				p.postal_code, p.phone, p.area_code, p.lat, p.lng, p.state_id, p.description,
				c.city_name, c.slug, c.state, ph.filename, ph.dir,
				rev_table.avg_rating
				FROM places p
				LEFT JOIN cities c ON p.city_id = c.city_id
				LEFT JOIN photos ph ON p.place_id = ph.place_id
				LEFT JOIN (
					SELECT *,
						AVG(rev.rating) AS avg_rating
						FROM reviews rev

					) rev_table ON p.place_id = rev_table.place_id
				WHERE p.city_id = :city_id AND p.status != 'trashed' AND paid = 1

				LIMIT :start, :limit";
	$stmt = $conn->prepare($query);
	$stmt->bindValue(':city_id', $query_city_id);
	$stmt->bindValue(':start', $start);
	$stmt->bindValue(':limit', $limit);
}

else{ // both $query_loc and $query_query empty
	$empty_city_and_query = true;
}

// now execute query
$stmt->execute();

// build results array
if($total_rows > 0) {
	while($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
		$place_id         = $row['place_id'];
		$place_name       = $row['place_name'];
		$address          = $row['address'];
		$cross_street     = $row['cross_street'];
		$place_city_name  = $row['city_name'];
		$place_city_slug  = $row['slug'];
		$place_state_id   = $row['state_id'];
		$place_state_abbr = $row['state'];
		$postal_code      = $row['postal_code'];
		$area_code        = $row['area_code'];
		$phone            = $row['phone'];
		$lat              = $row['lat'];
		$lng              = $row['lng'];
		$rating           = $row['avg_rating'];
		$description      = $row['description'];

		// short description
		$description = get_snippet($description, 20);

		// cat icon (just use blank img for now)
		$cat_icon = $baseurl . '/imgs/blank.png';

		// thumb
		if(!empty($row['filename'])) {
			$photo_url = $baseurl . '/place_pic_thumb/' . $row['dir'] . '/' . $row['filename'];
		}
		else {
			$photo_url = $cat_icon;
		}

		// clean place name
		$endash = html_entity_decode('&#x2013;', ENT_COMPAT, 'UTF-8');
		$place_name = str_replace($endash, "-", $place_name);

		$list_items[] = array(
			'place_id'         => $place_id,
			'place_name'       => e($place_name),
			'place_slug'       => to_slug($place_name),
			'address'          => e($address),
			'cross_street'     => e($cross_street),
			'place_city_name'  => $place_city_name,
			'place_city_slug'  => $place_city_slug,
			'place_state_abbr' => $place_state_abbr,
			'postal_code'      => e($postal_code),
			'area_code'        => e($area_code),
			'phone'            => e($phone),
			'lat'              => $lat,
			'lng'              => $lng,
			'cat_icon'         => $cat_icon,
			'photo_url'        => $photo_url,
			'rating'           => $rating,
			'description'      => $description
		);
	}
}

$location = '';
if(!empty($query_city_name) && !empty($query_state_abbr)) {
	$location = "$query_city_name, $query_state_abbr";
}

// translations
if(empty($location)) {
	$txt_html_title    = $txt_html_title_no_loc;
	$txt_meta_desc     = $txt_meta_desc_no_loc;
	$txt_main_title    = $txt_main_title_no_loc;

	$txt_html_title    = str_replace('%search_term%', e($query_query), $txt_html_title);
	$txt_meta_desc     = str_replace('%search_term%', e($query_query), $txt_meta_desc);
	$txt_main_title    = str_replace('%search_term%', e($query_query), $txt_main_title);
	$txt_empty_results = str_replace('%search_term%', e($query_query), $txt_empty_results);
}
else {
	$txt_html_title    = str_replace('%search_term%', e($query_query), $txt_html_title);
	$txt_html_title    = str_replace('%location%'   , $location      , $txt_html_title);
	$txt_meta_desc     = str_replace('%search_term%', e($query_query), $txt_meta_desc);
	$txt_meta_desc     = str_replace('%location%'   , $location      , $txt_meta_desc);
	$txt_main_title    = str_replace('%search_term%', e($query_query), $txt_main_title);
	$txt_main_title    = str_replace('%location%'   , $location      , $txt_main_title);
	$txt_empty_results = str_replace('%search_term%', e($query_query), $txt_empty_results);
}

// template file
require_once(__DIR__ . '/templates/tpl_searchresults6.php');

 

Link to comment
Share on other sites

I must be missing something here...    I also removed the die('Wrong city id') and it doesn't pull up both cities still.  Not sure what's wrong or what I have in the wrong place or what I'm supposed to leave out.  Something I'm doing wrong...

<?php
require_once(__DIR__ . '/inc/config.php');
?>
<?php
$total_rows = 0;
$response = array();

$query_city_id = (!empty($_GET['city_id'])) ? $_GET['city_id'] : 0;
$query_query   = (!empty($_GET['query']))   ? $_GET['query']   : '';  
$page          = (!empty($_GET['page']))    ? $_GET['page']    : 1;

// check vars
if(!is_numeric($query_city_id)) {
	die('Wrong city id');
}
$query_city_id = (int)$query_city_id;

// city details
$query_city_name  = '';
$query_state_abbr = '';



if (isset($_GET['city_id'])) {
    if ($_GET['city_id'] != 0) {
        $ids = explode(';', $_GET['city_id']) ;        // split multiple ids
        $k = count($ids);
        $placeholders = array_fill(0, $k, '?');
        $placestr = join(',', $placeholders);
        $stmt = $conn->prepare("SELECT city_name, state FROM cities WHERE city_id IN ($placestr)");
        $stmt->execute($ids); 
    }
    else {
        // if you want all cities then a where clause is not needed
        $stmt = $conn->query("SELECT city_name, state FROM cities");        
    }
    // process the stmt results here
}




	$row = $stmt->fetch(PDO::FETCH_ASSOC);
	$query_city_name = $row['city_name'];
	$query_state_abbr = $row['state'];


// paging vars
$limit = $items_per_page;
if($page > 1) {
	$offset = ($page-1) * $limit + 1;
}
else {
	$offset = 1;
}

// get page
if($page == 1) {
	$pag = '';
}
else {
	$pag = "- $txt_page $page";
}

// count total rows
if(!empty($query_city_id) && !empty($query_query)) {
	$query = "SELECT COUNT(*) AS total_rows
		FROM places
		WHERE city_id = :city_id AND status != 'trashed' AND paid = 1
			AND MATCH(place_name, description) AGAINST(:query) ";

	$stmt = $conn->prepare($query);
	$stmt->bindValue(':city_id', $query_city_id);
	$stmt->bindValue(':query', $query_query);
	$stmt->execute();
	$row = $stmt->fetch(PDO::FETCH_ASSOC);
	$total_rows = $row['total_rows'];
}
else if (empty($query_city_id) && !empty($query_query)) {
	$query = "SELECT COUNT(*) AS total_rows
		FROM places
		WHERE status != 'trashed' AND paid = 1
		AND MATCH(place_name, description) AGAINST(:query)";

	$stmt = $conn->prepare($query);
	$stmt->bindValue(':query', $query_query);
	$stmt->execute();
	$row = $stmt->fetch(PDO::FETCH_ASSOC);
	$total_rows = $row['total_rows'];
}
else if (!empty($query_city_id) && empty($query_query)) {
	$query = "SELECT COUNT(*) AS total_rows
		FROM places
		WHERE status != 'trashed' AND paid = 1 AND city_id = :city_id";

	$stmt = $conn->prepare($query);
	$stmt->bindValue(':city_id', $query_city_id);
	$stmt->execute();
	$row = $stmt->fetch(PDO::FETCH_ASSOC);
	$total_rows = $row['total_rows'];
}
else {
	$total_rows = 0;
}

$pager = new DirectoryApp\PageIterator($limit, $total_rows, $page);
$start = $pager->getStartRow();

// initialize empty city and query check
$empty_city_and_query = false;

/*--------------------------------------------------
LIST ITEMS LOGIC
--------------------------------------------------*/
if(!empty($query_city_id) && !empty($query_query)) {
	$query = "SELECT p.place_id, p.place_name, p.address, p.cross_street,
				p.postal_code, p.phone, p.area_code, p.lat, p.lng, p.state_id, p.description,
				c.city_name, c.slug, c.state, ph.filename, ph.dir,
				rev_table.avg_rating
				FROM places p
				LEFT JOIN cities c ON p.city_id = c.city_id
				LEFT JOIN photos ph ON p.place_id = ph.place_id
				LEFT JOIN (
					SELECT *,
						AVG(rev.rating) AS avg_rating
						FROM reviews rev

					) rev_table ON p.place_id = rev_table.place_id
				WHERE p.city_id = :city_id AND p.status != 'trashed' AND paid = 1
					AND MATCH(place_name, description) AGAINST(:query)

				LIMIT :start, :limit";
	$stmt = $conn->prepare($query);
	$stmt->bindValue(':city_id', $query_city_id);
	$stmt->bindValue(':query', $query_query);
	$stmt->bindValue(':start', $start);
	$stmt->bindValue(':limit', $limit);
}

else if(empty($query_city_id) && !empty($query_query)) {
	$query = "SELECT p.place_id, p.place_name, p.address, p.cross_street,
				p.postal_code, p.phone, p.area_code, p.lat, p.lng, p.state_id, p.description,
				c.city_name, c.slug, c.state, ph.filename, ph.dir,
				rev_table.avg_rating
				FROM places p
				LEFT JOIN cities c ON p.city_id = c.city_id
				LEFT JOIN photos ph ON p.place_id = ph.place_id
				LEFT JOIN (
					SELECT *,
						AVG(rev.rating) AS avg_rating
						FROM reviews rev
					) rev_table ON p.place_id = rev_table.place_id
				WHERE p.status != 'trashed' AND paid = 1
					AND MATCH(place_name, description) AGAINST(:query)

				LIMIT :start, :limit";
	$stmt = $conn->prepare($query);
	$stmt->bindValue(':query', $query_query);
	$stmt->bindValue(':start', $start);
	$stmt->bindValue(':limit', $limit);
}

else if(!empty($query_city_id) && empty($query_query)) {
	$query = "SELECT p.place_id, p.place_name, p.address, p.cross_street,
				p.postal_code, p.phone, p.area_code, p.lat, p.lng, p.state_id, p.description,
				c.city_name, c.slug, c.state, ph.filename, ph.dir,
				rev_table.avg_rating
				FROM places p
				LEFT JOIN cities c ON p.city_id = c.city_id
				LEFT JOIN photos ph ON p.place_id = ph.place_id
				LEFT JOIN (
					SELECT *,
						AVG(rev.rating) AS avg_rating
						FROM reviews rev

					) rev_table ON p.place_id = rev_table.place_id
				WHERE p.city_id = :city_id AND p.status != 'trashed' AND paid = 1

				LIMIT :start, :limit";
	$stmt = $conn->prepare($query);
	$stmt->bindValue(':city_id', $query_city_id);
	$stmt->bindValue(':start', $start);
	$stmt->bindValue(':limit', $limit);
}

else{ // both $query_loc and $query_query empty
	$empty_city_and_query = true;
}

// now execute query
$stmt->execute();

// build results array
if($total_rows > 0) {
	while($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
		$place_id         = $row['place_id'];
		$place_name       = $row['place_name'];
		$address          = $row['address'];
		$cross_street     = $row['cross_street'];
		$place_city_name  = $row['city_name'];
		$place_city_slug  = $row['slug'];
		$place_state_id   = $row['state_id'];
		$place_state_abbr = $row['state'];
		$postal_code      = $row['postal_code'];
		$area_code        = $row['area_code'];
		$phone            = $row['phone'];
		$lat              = $row['lat'];
		$lng              = $row['lng'];
		$rating           = $row['avg_rating'];
		$description      = $row['description'];

		// short description
		$description = get_snippet($description, 20);

		// cat icon (just use blank img for now)
		$cat_icon = $baseurl . '/imgs/blank.png';

		// thumb
		if(!empty($row['filename'])) {
			$photo_url = $baseurl . '/place_pic_thumb/' . $row['dir'] . '/' . $row['filename'];
		}
		else {
			$photo_url = $cat_icon;
		}

		// clean place name
		$endash = html_entity_decode('&#x2013;', ENT_COMPAT, 'UTF-8');
		$place_name = str_replace($endash, "-", $place_name);

		$list_items[] = array(
			'place_id'         => $place_id,
			'place_name'       => e($place_name),
			'place_slug'       => to_slug($place_name),
			'address'          => e($address),
			'cross_street'     => e($cross_street),
			'place_city_name'  => $place_city_name,
			'place_city_slug'  => $place_city_slug,
			'place_state_abbr' => $place_state_abbr,
			'postal_code'      => e($postal_code),
			'area_code'        => e($area_code),
			'phone'            => e($phone),
			'lat'              => $lat,
			'lng'              => $lng,
			'cat_icon'         => $cat_icon,
			'photo_url'        => $photo_url,
			'rating'           => $rating,
			'description'      => $description
		);
	}
}

$location = '';
if(!empty($query_city_name) && !empty($query_state_abbr)) {
	$location = "$query_city_name, $query_state_abbr";
}

// translations
if(empty($location)) {
	$txt_html_title    = $txt_html_title_no_loc;
	$txt_meta_desc     = $txt_meta_desc_no_loc;
	$txt_main_title    = $txt_main_title_no_loc;

	$txt_html_title    = str_replace('%search_term%', e($query_query), $txt_html_title);
	$txt_meta_desc     = str_replace('%search_term%', e($query_query), $txt_meta_desc);
	$txt_main_title    = str_replace('%search_term%', e($query_query), $txt_main_title);
	$txt_empty_results = str_replace('%search_term%', e($query_query), $txt_empty_results);
}
else {
	$txt_html_title    = str_replace('%search_term%', e($query_query), $txt_html_title);
	$txt_html_title    = str_replace('%location%'   , $location      , $txt_html_title);
	$txt_meta_desc     = str_replace('%search_term%', e($query_query), $txt_meta_desc);
	$txt_meta_desc     = str_replace('%location%'   , $location      , $txt_meta_desc);
	$txt_main_title    = str_replace('%search_term%', e($query_query), $txt_main_title);
	$txt_main_title    = str_replace('%location%'   , $location      , $txt_main_title);
	$txt_empty_results = str_replace('%search_term%', e($query_query), $txt_empty_results);
}

// template file
require_once(__DIR__ . '/templates/tpl_searchresults6.php');

 

Link to comment
Share on other sites

How do you know it is only pulling one city and not both? You only do a single fetch().

Where it says "// process the ststement results here" try

while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
    $query_city_name = $row['city_name'];
    $query_state_abbr = $row['state'];
    echo "$query_city_name, $query_state_abbr<br>";
}

 

Link to comment
Share on other sites

Yes, you are right.  It might be pulling more than one city.  The site is http://localbizseek.com/lbs/index6   I have the latest changes in it as shown here:

<?php
require_once(__DIR__ . '/inc/config.php');
?>
<?php
$total_rows = 0;
$response = array();

$query_city_id = (!empty($_GET['city_id'])) ? $_GET['city_id'] : 0;
$query_query   = (!empty($_GET['query']))   ? $_GET['query']   : '';  
$page          = (!empty($_GET['page']))    ? $_GET['page']    : 1;

// check vars
if(!is_numeric($query_city_id)) {

}
$query_city_id = (int)$query_city_id;

// city details
$query_city_name  = '';
$query_state_abbr = '';



if (isset($_GET['city_id'])) {
    if ($_GET['city_id'] != 0) {
        $ids = explode(';', $_GET['city_id']) ;        // split multiple ids
        $k = count($ids);
        $placeholders = array_fill(0, $k, '?');
        $placestr = join(',', $placeholders);
        $stmt = $conn->prepare("SELECT city_name, state FROM cities WHERE city_id IN ($placestr)");
        $stmt->execute($ids); 
    }
    else {
        // if you want all cities then a where clause is not needed
        $stmt = $conn->query("SELECT city_name, state FROM cities");        
    }
    // process the stmt results here
    while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
    $query_city_name = $row['city_name'];
    $query_state_abbr = $row['state'];
    echo "$query_city_name, $query_state_abbr<br>";
}
}


// paging vars
$limit = $items_per_page;
if($page > 1) {
	$offset = ($page-1) * $limit + 1;
}
else {
	$offset = 1;
}

// get page
if($page == 1) {
	$pag = '';
}
else {
	$pag = "- $txt_page $page";
}

// count total rows
if(!empty($query_city_id) && !empty($query_query)) {
	$query = "SELECT COUNT(*) AS total_rows
		FROM places
		WHERE city_id = :city_id AND status != 'trashed' AND paid = 1
			AND MATCH(place_name, description) AGAINST(:query) ";

	$stmt = $conn->prepare($query);
	$stmt->bindValue(':city_id', $query_city_id);
	$stmt->bindValue(':query', $query_query);
	$stmt->execute();
	$row = $stmt->fetch(PDO::FETCH_ASSOC);
	$total_rows = $row['total_rows'];
}
else if (empty($query_city_id) && !empty($query_query)) {
	$query = "SELECT COUNT(*) AS total_rows
		FROM places
		WHERE status != 'trashed' AND paid = 1
		AND MATCH(place_name, description) AGAINST(:query)";

	$stmt = $conn->prepare($query);
	$stmt->bindValue(':query', $query_query);
	$stmt->execute();
	$row = $stmt->fetch(PDO::FETCH_ASSOC);
	$total_rows = $row['total_rows'];
}
else if (!empty($query_city_id) && empty($query_query)) {
	$query = "SELECT COUNT(*) AS total_rows
		FROM places
		WHERE status != 'trashed' AND paid = 1 AND city_id = :city_id";

	$stmt = $conn->prepare($query);
	$stmt->bindValue(':city_id', $query_city_id);
	$stmt->execute();
	$row = $stmt->fetch(PDO::FETCH_ASSOC);
	$total_rows = $row['total_rows'];
}
else {
	$total_rows = 0;
}

$pager = new DirectoryApp\PageIterator($limit, $total_rows, $page);
$start = $pager->getStartRow();

// initialize empty city and query check
$empty_city_and_query = false;

/*--------------------------------------------------
LIST ITEMS LOGIC
--------------------------------------------------*/
if(!empty($query_city_id) && !empty($query_query)) {
	$query = "SELECT p.place_id, p.place_name, p.address, p.cross_street,
				p.postal_code, p.phone, p.area_code, p.lat, p.lng, p.state_id, p.description,
				c.city_name, c.slug, c.state, ph.filename, ph.dir,
				rev_table.avg_rating
				FROM places p
				LEFT JOIN cities c ON p.city_id = c.city_id
				LEFT JOIN photos ph ON p.place_id = ph.place_id
				LEFT JOIN (
					SELECT *,
						AVG(rev.rating) AS avg_rating
						FROM reviews rev

					) rev_table ON p.place_id = rev_table.place_id
				WHERE p.city_id = :city_id AND p.status != 'trashed' AND paid = 1
					AND MATCH(place_name, description) AGAINST(:query)

				LIMIT :start, :limit";
	$stmt = $conn->prepare($query);
	$stmt->bindValue(':city_id', $query_city_id);
	$stmt->bindValue(':query', $query_query);
	$stmt->bindValue(':start', $start);
	$stmt->bindValue(':limit', $limit);
}

else if(empty($query_city_id) && !empty($query_query)) {
	$query = "SELECT p.place_id, p.place_name, p.address, p.cross_street,
				p.postal_code, p.phone, p.area_code, p.lat, p.lng, p.state_id, p.description,
				c.city_name, c.slug, c.state, ph.filename, ph.dir,
				rev_table.avg_rating
				FROM places p
				LEFT JOIN cities c ON p.city_id = c.city_id
				LEFT JOIN photos ph ON p.place_id = ph.place_id
				LEFT JOIN (
					SELECT *,
						AVG(rev.rating) AS avg_rating
						FROM reviews rev
					) rev_table ON p.place_id = rev_table.place_id
				WHERE p.status != 'trashed' AND paid = 1
					AND MATCH(place_name, description) AGAINST(:query)

				LIMIT :start, :limit";
	$stmt = $conn->prepare($query);
	$stmt->bindValue(':query', $query_query);
	$stmt->bindValue(':start', $start);
	$stmt->bindValue(':limit', $limit);
}

else if(!empty($query_city_id) && empty($query_query)) {
	$query = "SELECT p.place_id, p.place_name, p.address, p.cross_street,
				p.postal_code, p.phone, p.area_code, p.lat, p.lng, p.state_id, p.description,
				c.city_name, c.slug, c.state, ph.filename, ph.dir,
				rev_table.avg_rating
				FROM places p
				LEFT JOIN cities c ON p.city_id = c.city_id
				LEFT JOIN photos ph ON p.place_id = ph.place_id
				LEFT JOIN (
					SELECT *,
						AVG(rev.rating) AS avg_rating
						FROM reviews rev

					) rev_table ON p.place_id = rev_table.place_id
				WHERE p.city_id = :city_id AND p.status != 'trashed' AND paid = 1

				LIMIT :start, :limit";
	$stmt = $conn->prepare($query);
	$stmt->bindValue(':city_id', $query_city_id);
	$stmt->bindValue(':start', $start);
	$stmt->bindValue(':limit', $limit);
}

else{ // both $query_loc and $query_query empty
	$empty_city_and_query = true;
}

// now execute query
$stmt->execute();

// build results array
if($total_rows > 0) {
	while($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
		$place_id         = $row['place_id'];
		$place_name       = $row['place_name'];
		$address          = $row['address'];
		$cross_street     = $row['cross_street'];
		$place_city_name  = $row['city_name'];
		$place_city_slug  = $row['slug'];
		$place_state_id   = $row['state_id'];
		$place_state_abbr = $row['state'];
		$postal_code      = $row['postal_code'];
		$area_code        = $row['area_code'];
		$phone            = $row['phone'];
		$lat              = $row['lat'];
		$lng              = $row['lng'];
		$rating           = $row['avg_rating'];
		$description      = $row['description'];

		// short description
		$description = get_snippet($description, 20);

		// cat icon (just use blank img for now)
		$cat_icon = $baseurl . '/imgs/blank.png';

		// thumb
		if(!empty($row['filename'])) {
			$photo_url = $baseurl . '/place_pic_thumb/' . $row['dir'] . '/' . $row['filename'];
		}
		else {
			$photo_url = $cat_icon;
		}

		// clean place name
		$endash = html_entity_decode('&#x2013;', ENT_COMPAT, 'UTF-8');
		$place_name = str_replace($endash, "-", $place_name);

		$list_items[] = array(
			'place_id'         => $place_id,
			'place_name'       => e($place_name),
			'place_slug'       => to_slug($place_name),
			'address'          => e($address),
			'cross_street'     => e($cross_street),
			'place_city_name'  => $place_city_name,
			'place_city_slug'  => $place_city_slug,
			'place_state_abbr' => $place_state_abbr,
			'postal_code'      => e($postal_code),
			'area_code'        => e($area_code),
			'phone'            => e($phone),
			'lat'              => $lat,
			'lng'              => $lng,
			'cat_icon'         => $cat_icon,
			'photo_url'        => $photo_url,
			'rating'           => $rating,
			'description'      => $description
		);
	}
}

$location = '';
if(!empty($query_city_name) && !empty($query_state_abbr)) {
	$location = "$query_city_name, $query_state_abbr";
}

// translations
if(empty($location)) {
	$txt_html_title    = $txt_html_title_no_loc;
	$txt_meta_desc     = $txt_meta_desc_no_loc;
	$txt_main_title    = $txt_main_title_no_loc;

	$txt_html_title    = str_replace('%search_term%', e($query_query), $txt_html_title);
	$txt_meta_desc     = str_replace('%search_term%', e($query_query), $txt_meta_desc);
	$txt_main_title    = str_replace('%search_term%', e($query_query), $txt_main_title);
	$txt_empty_results = str_replace('%search_term%', e($query_query), $txt_empty_results);
}
else {
	$txt_html_title    = str_replace('%search_term%', e($query_query), $txt_html_title);
	$txt_html_title    = str_replace('%location%'   , $location      , $txt_html_title);
	$txt_meta_desc     = str_replace('%search_term%', e($query_query), $txt_meta_desc);
	$txt_meta_desc     = str_replace('%location%'   , $location      , $txt_meta_desc);
	$txt_main_title    = str_replace('%search_term%', e($query_query), $txt_main_title);
	$txt_main_title    = str_replace('%location%'   , $location      , $txt_main_title);
	$txt_empty_results = str_replace('%search_term%', e($query_query), $txt_empty_results);
}

// template file
require_once(__DIR__ . '/templates/tpl_searchresults6.php');

 

Link to comment
Share on other sites

Php Code problem where I cannot figure out how to get the code right to be able to select more than two cities for it to search and display two cities results. It does one at a time or everything in the database but not a selected number.

I will include some Select side code first below and right after that some of the processing page code. There is a third page of code as well which is the output code I think. If anyone needs to see that I can post that later. I'm not sure the solution needs to address that page but I might be wrong there.

I've put this up for solutions on other forums and nobody has the answer that fixes it yet. It could be that I'm missing something but that's the latest code changes... Need Help bad.

Quote



 <form id="main-search-form" method="GET" action="<?= $baseurl; ?>/_searchresults6.php" role="search">


        <select id="query-input" name="city_id" style="width:28.8%" style="height:69px" required>

            <option value="">Select Area</option>

            <option value="3;1">Ches & VB</option>
            <option value="3">Chesapeake , VA</option>
            <option value="9">Hampton , VA</option> 
            <option value="10">Newport News , VA</option>           
            <option value="2">Norfolk , VA</option>         
            <option value="12">Poquoson , VA</option>   
            <option value="4">Portsmouth , VA</option>              
            <option value="5">Suffolk , VA</option>             
            <option value="1">Virginia Beach , VA</option>  
            <option value="11">Williamsburg , VA</option>
            <option value="0">All Active US Cities</option>



            </select>
                            </form>

//This next code is from the processing page//

<?php
require_once(__DIR__ . '/inc/config.php');
?>
<?php
$total_rows = 0;
$response = array();

$query_city_id = (!empty($_GET['city_id'])) ? $_GET['city_id'] : 0;
$query_query   = (!empty($_GET['query']))   ? $_GET['query']   : '';  
$page          = (!empty($_GET['page']))    ? $_GET['page']    : 1;

// check vars
if(!is_numeric($query_city_id)) {

}
$query_city_id = (int)$query_city_id;

// city details
$query_city_name  = '';
$query_state_abbr = '';



if (isset($_GET['city_id'])) {
    if ($_GET['city_id'] != 0) {
        $ids = explode(';', $_GET['city_id']) ;        // split multiple ids
        $k = count($ids);
        $placeholders = array_fill(0, $k, '?');
        $placestr = join(',', $placeholders);
        $stmt = $conn->prepare("SELECT city_name, state FROM cities WHERE city_id IN ($placestr)");
        $stmt->execute($ids); 
    }
    else {
        // if you want all cities then a where clause is not needed
        $stmt = $conn->query("SELECT city_name, state FROM cities");        
    }
    // process the stmt results here
    while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
    $query_city_name = $row['city_name'];
    $query_state_abbr = $row['state'];
    echo "$query_city_name, $query_state_abbr<br>";
}
}


// paging vars
$limit = $items_per_page;
if($page > 1) {
	$offset = ($page-1) * $limit + 1;
}
else {
	$offset = 1;
}

// get page
if($page == 1) {
	$pag = '';
}
else {
	$pag = "- $txt_page $page";
}

// count total rows
if(!empty($query_city_id) && !empty($query_query)) {
	$query = "SELECT COUNT(*) AS total_rows
		FROM places
		WHERE city_id = :city_id AND status != 'trashed' AND paid = 1
			AND MATCH(place_name, description) AGAINST(:query) ";

	$stmt = $conn->prepare($query);
	$stmt->bindValue(':city_id', $query_city_id);
	$stmt->bindValue(':query', $query_query);
	$stmt->execute();
	$row = $stmt->fetch(PDO::FETCH_ASSOC);
	$total_rows = $row['total_rows'];
}
else if (empty($query_city_id) && !empty($query_query)) {
	$query = "SELECT COUNT(*) AS total_rows
		FROM places
		WHERE status != 'trashed' AND paid = 1
		AND MATCH(place_name, description) AGAINST(:query)";

	$stmt = $conn->prepare($query);
	$stmt->bindValue(':query', $query_query);
	$stmt->execute();
	$row = $stmt->fetch(PDO::FETCH_ASSOC);
	$total_rows = $row['total_rows'];
}
else if (!empty($query_city_id) && empty($query_query)) {
	$query = "SELECT COUNT(*) AS total_rows
		FROM places
		WHERE status != 'trashed' AND paid = 1 AND city_id = :city_id";

	$stmt = $conn->prepare($query);
	$stmt->bindValue(':city_id', $query_city_id);
	$stmt->execute();
	$row = $stmt->fetch(PDO::FETCH_ASSOC);
	$total_rows = $row['total_rows'];
}
else {
	$total_rows = 0;
}

$pager = new DirectoryApp\PageIterator($limit, $total_rows, $page);
$start = $pager->getStartRow();

// initialize empty city and query check
$empty_city_and_query = false;

/*--------------------------------------------------
LIST ITEMS LOGIC
--------------------------------------------------*/
if(!empty($query_city_id) && !empty($query_query)) {
	$query = "SELECT p.place_id, p.place_name, p.address, p.cross_street,
				p.postal_code, p.phone, p.area_code, p.lat, p.lng, p.state_id, p.description,
				c.city_name, c.slug, c.state, ph.filename, ph.dir,
				rev_table.avg_rating
				FROM places p
				LEFT JOIN cities c ON p.city_id = c.city_id
				LEFT JOIN photos ph ON p.place_id = ph.place_id
				LEFT JOIN (
					SELECT *,
						AVG(rev.rating) AS avg_rating
						FROM reviews rev

					) rev_table ON p.place_id = rev_table.place_id
				WHERE p.city_id = :city_id AND p.status != 'trashed' AND paid = 1
					AND MATCH(place_name, description) AGAINST(:query)

				LIMIT :start, :limit";
	$stmt = $conn->prepare($query);
	$stmt->bindValue(':city_id', $query_city_id);
	$stmt->bindValue(':query', $query_query);
	$stmt->bindValue(':start', $start);
	$stmt->bindValue(':limit', $limit);
}

else if(empty($query_city_id) && !empty($query_query)) {
	$query = "SELECT p.place_id, p.place_name, p.address, p.cross_street,
				p.postal_code, p.phone, p.area_code, p.lat, p.lng, p.state_id, p.description,
				c.city_name, c.slug, c.state, ph.filename, ph.dir,
				rev_table.avg_rating
				FROM places p
				LEFT JOIN cities c ON p.city_id = c.city_id
				LEFT JOIN photos ph ON p.place_id = ph.place_id
				LEFT JOIN (
					SELECT *,
						AVG(rev.rating) AS avg_rating
						FROM reviews rev
					) rev_table ON p.place_id = rev_table.place_id
				WHERE p.status != 'trashed' AND paid = 1
					AND MATCH(place_name, description) AGAINST(:query)

				LIMIT :start, :limit";
	$stmt = $conn->prepare($query);
	$stmt->bindValue(':query', $query_query);
	$stmt->bindValue(':start', $start);
	$stmt->bindValue(':limit', $limit);
}

else if(!empty($query_city_id) && empty($query_query)) {
	$query = "SELECT p.place_id, p.place_name, p.address, p.cross_street,
				p.postal_code, p.phone, p.area_code, p.lat, p.lng, p.state_id, p.description,
				c.city_name, c.slug, c.state, ph.filename, ph.dir,
				rev_table.avg_rating
				FROM places p
				LEFT JOIN cities c ON p.city_id = c.city_id
				LEFT JOIN photos ph ON p.place_id = ph.place_id
				LEFT JOIN (
					SELECT *,
						AVG(rev.rating) AS avg_rating
						FROM reviews rev

					) rev_table ON p.place_id = rev_table.place_id
				WHERE p.city_id = :city_id AND p.status != 'trashed' AND paid = 1

				LIMIT :start, :limit";
	$stmt = $conn->prepare($query);
	$stmt->bindValue(':city_id', $query_city_id);
	$stmt->bindValue(':start', $start);
	$stmt->bindValue(':limit', $limit);
}

else{ // both $query_loc and $query_query empty
	$empty_city_and_query = true;
}

// now execute query
$stmt->execute();

 

 

Link to comment
Share on other sites

you need to start by specifically defining what you are trying to accomplish, including what the scope and limitations are. then write and test just the code needed to accomplish the stated goal (you currently have a bunch of code and queries written out for each combination of search fields - this is not how to do this, you would dynamically build a query with just the parts it needs.)

you have shown one example of a composite value, the 1;3 for Chesapeake or Virginia Beach. is this the only multiple location or are you planning on producing all possible combinations once you get this working for the one example OR do you actually just want to allow any of the listed cities to be picked? if your assignment is just to allow multiple cities to be picked, you have been given the answer on at least one of the forums, add the multiple attribute to the <select tag and make the select name attribute an array. this will let you select one or more cities from the listed cities. note: you should be dynamically producing the select option choices from the available cities, the form and the form processing code should be on the same page, and you should make the form 'sticky' by selecting any option choice(s) that have already been selected and submitted.

next, for the form processing code, start small. get this city id code to work first, then add other search fields. your form processing code should detect and validate any inputs before using them, as already stated - dynamically build the query, fetch the data from the query into a php array variable, then just test and loop over this variable to produce the output. since you are doing pagination, you need two queries, the first one gets a count of the matching rows, the second one gets the logical page of data. the table, join, and where clauses in both these queries must be the same and should just be built once, then re-used in both queries.

Link to comment
Share on other sites

Yes,  this the only multiple location "1;3" I am trying to get to work and then once I get it working then I will be producing all possible combinations as your question stated.  So I don't want a multiple select just a pre coded as with 1;3 type of selector. 

I have tried the other code instructions given so far but maybe I don't know where that code should have gone.  I don't know if I'm doing it right.  I guess I need a bit more help with this... to get it plugged in right.

 

Link to comment
Share on other sites

Yes,  this the only multiple location "1;3" I am trying to get to work and then once I get it working then I will be producing all possible combinations as your question stated.  So I don't want a multiple select just a pre coded as with 1;3 type of selector. 

I have tried the other code instructions given so far but maybe I don't know where that code should have gone.  I don't know if I'm doing it right.  I guess I need a bit more help with this... to get it plugged in right.

The code worked for everything already prior to this change.  The only thing that is not working is when I try to get one of the select options to be more than one variable such as 1;3.  That is what I can't get it to do.  Everything else works right. 

 

Link to comment
Share on other sites

Here is the error messages I'm now getting with

	//First Page with Selector//

		<form id="main-search-form" method="GET" action="<?= $baseurl; ?>/_searchresults6.php" role="search">
		    
	    
		    <select id="query-input" name="city_id[]" style="width:28.8%" style="height:69px" required>
					                
		        <option value="">Select Area</option>
		        
		        <option value="3;1">Ches & VB</option>
		        <option value="3">Chesapeake , VA</option>
				<option value="9">Hampton , VA</option>	
				<option value="10">Newport News , VA</option>			
				<option value="2">Norfolk , VA</option>			
				<option value="12">Poquoson , VA</option>	
				<option value="4">Portsmouth , VA</option>				
                <option value="5">Suffolk , VA</option>				
                <option value="1">Virginia Beach , VA</option>	
				<option value="11">Williamsburg , VA</option>
                <option value="0">All Active US Cities</option>

		
							
          </select></form>

//Second Page code with newest Changes//

<?php
require_once(__DIR__ . '/inc/config.php');
?>
<?php
$total_rows = 0;
$response = array();

$query_city_id[] = (!empty($_GET['city_id'])) ? $_GET['city_id'] : 0;  
$query_city_id = (!empty($_GET['city_id'])) ? $_GET['city_id'] : 0;
$query_query   = (!empty($_GET['query']))   ? $_GET['query']   : '';  
$page          = (!empty($_GET['page']))    ? $_GET['page']    : 1;


// city details
$query_city_name  = '';
$query_state_abbr = '';
if(!empty($query_city_id)) {
	$query = "SELECT city_name, state FROM cities WHERE city_id = :query_city_id";
	$stmt = $conn->prepare($query);
	$stmt->bindValue(':query_city_id', $query_city_id);
	$stmt->execute();
	$row = $stmt->fetch(PDO::FETCH_ASSOC);
	$query_city_name = $row['city_name'];
	$query_state_abbr = $row['state'];
}

// paging vars
$limit = $items_per_page;
if($page > 1) {
	$offset = ($page-1) * $limit + 1;
}
else {
	$offset = 1;
}

// get page
if($page == 1) {
	$pag = '';
}
else {
	$pag = "- $txt_page $page";
}

// count total rows
if(!empty($query_city_id) && !empty($query_query)) {
	$query = "SELECT COUNT(*) AS total_rows
		FROM places
		WHERE city_id = :city_id AND status != 'trashed' AND paid = 1
			AND MATCH(place_name, description) AGAINST(:query) ";

	$stmt = $conn->prepare($query);
	$stmt->bindValue(':city_id', $query_city_id);
	$stmt->bindValue(':query', $query_query);
	$stmt->execute();
	$row = $stmt->fetch(PDO::FETCH_ASSOC);
	$total_rows = $row['total_rows'];
}
else if (empty($query_city_id) && !empty($query_query)) {
	$query = "SELECT COUNT(*) AS total_rows
		FROM places
		WHERE status != 'trashed' AND paid = 1
		AND MATCH(place_name, description) AGAINST(:query)";

	$stmt = $conn->prepare($query);
	$stmt->bindValue(':query', $query_query);
	$stmt->execute();
	$row = $stmt->fetch(PDO::FETCH_ASSOC);
	$total_rows = $row['total_rows'];
}
else if (!empty($query_city_id) && empty($query_query)) {
	$query = "SELECT COUNT(*) AS total_rows
		FROM places
		WHERE status != 'trashed' AND paid = 1 AND city_id = :city_id";

	$stmt = $conn->prepare($query);
	$stmt->bindValue(':city_id', $query_city_id);
	$stmt->execute();
	$row = $stmt->fetch(PDO::FETCH_ASSOC);
	$total_rows = $row['total_rows'];
}
else {
	$total_rows = 0;
}

$pager = new DirectoryApp\PageIterator($limit, $total_rows, $page);
$start = $pager->getStartRow();

// initialize empty city and query check
$empty_city_and_query = false;

/*--------------------------------------------------
LIST ITEMS LOGIC
--------------------------------------------------*/
if(!empty($query_city_id) && !empty($query_query)) {
	$query = "SELECT p.place_id, p.place_name, p.address, p.cross_street,
				p.postal_code, p.phone, p.area_code, p.lat, p.lng, p.state_id, p.description,
				c.city_name, c.slug, c.state, ph.filename, ph.dir,
				rev_table.avg_rating
				FROM places p
				LEFT JOIN cities c ON p.city_id = c.city_id
				LEFT JOIN photos ph ON p.place_id = ph.place_id
				LEFT JOIN (
					SELECT *,
						AVG(rev.rating) AS avg_rating
						FROM reviews rev

					) rev_table ON p.place_id = rev_table.place_id
				WHERE p.city_id = :city_id AND p.status != 'trashed' AND paid = 1
					AND MATCH(place_name, description) AGAINST(:query)

				LIMIT :start, :limit";
	$stmt = $conn->prepare($query);
	$stmt->bindValue(':city_id', $query_city_id);
	$stmt->bindValue(':query', $query_query);
	$stmt->bindValue(':start', $start);
	$stmt->bindValue(':limit', $limit);
}

else if(empty($query_city_id) && !empty($query_query)) {
	$query = "SELECT p.place_id, p.place_name, p.address, p.cross_street,
				p.postal_code, p.phone, p.area_code, p.lat, p.lng, p.state_id, p.description,
				c.city_name, c.slug, c.state, ph.filename, ph.dir,
				rev_table.avg_rating
				FROM places p
				LEFT JOIN cities c ON p.city_id = c.city_id
				LEFT JOIN photos ph ON p.place_id = ph.place_id
				LEFT JOIN (
					SELECT *,
						AVG(rev.rating) AS avg_rating
						FROM reviews rev
					) rev_table ON p.place_id = rev_table.place_id
				WHERE p.status != 'trashed' AND paid = 1
					AND MATCH(place_name, description) AGAINST(:query)

				LIMIT :start, :limit";
	$stmt = $conn->prepare($query);
	$stmt->bindValue(':query', $query_query);
	$stmt->bindValue(':start', $start);
	$stmt->bindValue(':limit', $limit);
}

else if(!empty($query_city_id) && empty($query_query)) {
	$query = "SELECT p.place_id, p.place_name, p.address, p.cross_street,
				p.postal_code, p.phone, p.area_code, p.lat, p.lng, p.state_id, p.description,
				c.city_name, c.slug, c.state, ph.filename, ph.dir,
				rev_table.avg_rating
				FROM places p
				LEFT JOIN cities c ON p.city_id = c.city_id
				LEFT JOIN photos ph ON p.place_id = ph.place_id
				LEFT JOIN (
					SELECT *,
						AVG(rev.rating) AS avg_rating
						FROM reviews rev

					) rev_table ON p.place_id = rev_table.place_id
				WHERE p.city_id = :city_id AND p.status != 'trashed' AND paid = 1

				LIMIT :start, :limit";
	$stmt = $conn->prepare($query);
	$stmt->bindValue(':city_id', $query_city_id);
	$stmt->bindValue(':start', $start);
	$stmt->bindValue(':limit', $limit);
}

else{ // both $query_loc and $query_query empty
	$empty_city_and_query = true;
}

// now execute query
$stmt->execute();

// build results array
if($total_rows > 0) {
	while($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
		$place_id         = $row['place_id'];
		$place_name       = $row['place_name'];
		$address          = $row['address'];
		$cross_street     = $row['cross_street'];
		$place_city_name  = $row['city_name'];
		$place_city_slug  = $row['slug'];
		$place_state_id   = $row['state_id'];
		$place_state_abbr = $row['state'];
		$postal_code      = $row['postal_code'];
		$area_code        = $row['area_code'];
		$phone            = $row['phone'];
		$lat              = $row['lat'];
		$lng              = $row['lng'];
		$rating           = $row['avg_rating'];
		$description      = $row['description'];

		// short description
		$description = get_snippet($description, 20);

		// cat icon (just use blank img for now)
		$cat_icon = $baseurl . '/imgs/blank.png';

		// thumb
		if(!empty($row['filename'])) {
			$photo_url = $baseurl . '/place_pic_thumb/' . $row['dir'] . '/' . $row['filename'];
		}
		else {
			$photo_url = $cat_icon;
		}

		// clean place name
		$endash = html_entity_decode('&#x2013;', ENT_COMPAT, 'UTF-8');
		$place_name = str_replace($endash, "-", $place_name);

		$list_items[] = array(
			'place_id'         => $place_id,
			'place_name'       => e($place_name),
			'place_slug'       => to_slug($place_name),
			'address'          => e($address),
			'cross_street'     => e($cross_street),
			'place_city_name'  => $place_city_name,
			'place_city_slug'  => $place_city_slug,
			'place_state_abbr' => $place_state_abbr,
			'postal_code'      => e($postal_code),
			'area_code'        => e($area_code),
			'phone'            => e($phone),
			'lat'              => $lat,
			'lng'              => $lng,
			'cat_icon'         => $cat_icon,
			'photo_url'        => $photo_url,
			'rating'           => $rating,
			'description'      => $description
		);
	}
}

$location = '';
if(!empty($query_city_name) && !empty($query_state_abbr)) {
	$location = "$query_city_name, $query_state_abbr";
}

// translations
if(empty($location)) {
	$txt_html_title    = $txt_html_title_no_loc;
	$txt_meta_desc     = $txt_meta_desc_no_loc;
	$txt_main_title    = $txt_main_title_no_loc;

	$txt_html_title    = str_replace('%search_term%', e($query_query), $txt_html_title);
	$txt_meta_desc     = str_replace('%search_term%', e($query_query), $txt_meta_desc);
	$txt_main_title    = str_replace('%search_term%', e($query_query), $txt_main_title);
	$txt_empty_results = str_replace('%search_term%', e($query_query), $txt_empty_results);
}
else {
	$txt_html_title    = str_replace('%search_term%', e($query_query), $txt_html_title);
	$txt_html_title    = str_replace('%location%'   , $location      , $txt_html_title);
	$txt_meta_desc     = str_replace('%search_term%', e($query_query), $txt_meta_desc);
	$txt_meta_desc     = str_replace('%location%'   , $location      , $txt_meta_desc);
	$txt_main_title    = str_replace('%search_term%', e($query_query), $txt_main_title);
	$txt_main_title    = str_replace('%location%'   , $location      , $txt_main_title);
	$txt_empty_results = str_replace('%search_term%', e($query_query), $txt_empty_results);
}

// template file
require_once(__DIR__ . '/templates/tpl_searchresults.php');

he below listed code;

Error Number: 2 
Error String: explode() expects parameter 2 to be string, array given 
Error Line: 26 
Error File: /home/admin/public_html/lbs/_searchresults6.php 
Terminating scriptError Number: 2 
Error String: array_fill(): Number of elements must be positive 
Error Line: 28 
Error File: /home/admin/public_html/lbs/_searchresults6.php 
Terminating scriptError Number: 2 
Error String: join(): Invalid arguments passed 
Error Line: 29 
Error File: /home/admin/public_html/lbs/_searchresults6.php 
Terminating scriptUncaught exception: SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ')' at line 1
Terminating script

Link to comment
Share on other sites

Whoever can help me get the code right for this to work I will pay and also put on company pay for whenever I need this kind of help. 

I have this multiple variable problem to solve

and

I want to figure out also how to get the drop down to be auto populating where you type in 3 letter or so and it pulls up the city to search. 

The first one I want to solve first and then second one after. 

Let me know who wants to do this.  

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.