Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 10 of 10
  1. #1
    New to the CF scene
    Join Date
    Apr 2019
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Unhappy Cannot get Site to Process Multiple Variables and Display Results

    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:


    Code:
            <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.



    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 = :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');
    Last edited by vinyl-junkie; Apr 13th, 2019 at 06:08 AM. Reason: added code tags

  2. #2
    Master Coder sunfighter's Avatar
    Join Date
    Jan 2011
    Location
    Washington
    Posts
    8,035
    Thanks
    37
    Thanked 1,076 Times in 1,072 Posts
    If you use the multiple option in the <select> tag with a submit button you can choose more then one option.
    But using check boxes maybe a better solution.
    Last edited by sunfighter; Apr 13th, 2019 at 04:39 PM.
    Evolution - The non-random survival of random variants.
    Physics is actually atoms trying to understand themselves.

  3. #3
    New to the CF scene
    Join Date
    Apr 2019
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Yes I tried that too but nothing works and I need the coding solution for the processing page side. It isn't set up for multiple variables and I'm not sure how to solve that. I don't know what to do to the code for it to accept and process multiple variables.

  4. #4
    Super Moderator
    Join Date
    May 2005
    Location
    Southern tip of Silicon Valley
    Posts
    3,365
    Thanks
    2
    Thanked 234 Times in 227 Posts
    Quote Originally Posted by BobJohnson View Post
    Yes I tried that too but nothing works and I need the coding solution for the processing page side. It isn't set up for multiple variables and I'm not sure how to solve that. I don't know what to do to the code for it to accept and process multiple variables.
    I'm not sure if you mean that you don't know how to define the html select tag to accept multiple items or you don't know how to retrieve them in the php script or you don't know how to do either of them.
    html:
    Code:
    <select id="query-input" name="city_id[]" multiple="multiple" style="width:28.8%" style="height:69px" required>
    php:
    PHP Code:
    $query_city_id[] = (!empty($_GET['city_id'])) ? $_GET['city_id'] : 0
    Then in the sql statement, you would use an IN clause.
    Code:
    $query = "SELECT city_name, state FROM cities WHERE city_id IN (:query_city_id");
    Note: My php skills are very rusty, so it might need a slight tweak

  5. #5
    New Coder
    Join Date
    Mar 2018
    Posts
    22
    Thanks
    0
    Thanked 1 Time in 1 Post
    Code:
    if (!empty($_GET['city_id'])
    {
    $myinsecuredata=$_GET["city_id"];
    
    $query=$db->prepare("SELECT city_name, state FROM cities WHERE city_id IN ?"););
    $query->excute(array($myinsecuredata));
    }
    If you use PDO.
    Not sure but i hope it helps.

  6. #6
    New to the CF scene
    Join Date
    Apr 2019
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks I'll these changes... very good information.

  7. #7
    New to the CF scene
    Join Date
    Apr 2019
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts
    The one marked code I know wher that needs to go. The php I know where that needs to go but the sql statement I'm not sure where that goes in the code. Do I need to remove anything if the php code and sql statement code is added to the code?

  8. #8
    New to the CF scene
    Join Date
    Apr 2019
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by FishMonger View Post
    I'm not sure if you mean that you don't know how to define the html select tag to accept multiple items or you don't know how to retrieve them in the php script or you don't know how to do either of them.
    html:
    Code:
    <select id="query-input" name="city_id[]" multiple="multiple" style="width:28.8%" style="height:69px" required>
    php:
    PHP Code:
    $query_city_id[] = (!empty($_GET['city_id'])) ? $_GET['city_id'] : 0
    Then in the sql statement, you would use an IN clause.
    Code:
    $query = "SELECT city_name, state FROM cities WHERE city_id IN (:query_city_id");
    Note: My php skills are very rusty, so it might need a slight tweak
    Here is the current error code I am getting:

    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

    Line 26 is: $row = $stmt->fetch(PDO::FETCH_ASSOC);


    Here is the Select page code:


    PHP Code:
            <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>
    Here is the Processing page code:
    PHP 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)) {

    }
    $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($description20);

            
    // 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');
    Last edited by FishMonger; Apr 17th, 2019 at 01:15 AM.

  9. #9
    New to the CF scene
    Join Date
    Apr 2019
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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.

  10. #10
    Super Moderator
    Join Date
    May 2005
    Location
    Southern tip of Silicon Valley
    Posts
    3,365
    Thanks
    2
    Thanked 234 Times in 227 Posts
    1) You forgot to add the "multiple" attribute to the html select statement.
    PHP Code:
    <select id="query-input" name="city_id[]" multiple="multiple" style="width:28.8%" style="height:69px" required
    2) Why do you have this statement?
    PHP Code:
    $query_city_id = (int)$query_city_id
    It is not doing what you want and I suspect you don't understand what it does.

    3) Your sql select statement is wrong. If you want to select multiple city id's (via the $query_city_id array), you should use an IN clause instead of = equality. It would be best to use a placeholders like jacxx showed.
    PHP Code:
    $query $db->prepare("SELECT city_name, state FROM cities WHERE city_id IN ?"););
    $stmt $conn->prepare($query);
    $stmt->execute(array($query_city_id)); 


 

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •