Jump to content

BobJohnson

Members
  • Posts

    17
  • Joined

  • Last visited

Recent Profile Visitors

The recent visitors block is disabled and is not being shown to other users.

BobJohnson's Achievements

Member

Member (2/5)

0

Reputation

  1. 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.
  2. Line 26 is " $row = $stmt->fetch(PDO::FETCH_ASSOC);"
  3. 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 1Terminating script
  4. 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.
  5. 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.
  6. 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.
  7. 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');
  8. 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');
  9. 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');
  10. 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');
  11. 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...
  12. 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.
  13. Are those code items you selected the only code items that need to be changed to make it work?
  14. You are very fast and good at this... I didn't notice you edited it. I will use "3,1" as the select format. What items needs to be adjusted in the code? or did you change it to do it?
  15. 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>
×
×
  • 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.