www.webdeveloper.com
Results 1 to 5 of 5

Thread: php search engine

  1. #1
    Join Date
    Oct 2010
    Posts
    13

    php search engine

    hi there. Ive got a search engine that doesn't work. So far it's ment to say if there's any resilts found. However when i'm typing in the keywords it's saying no results found. could anyone please take a look??

    Code:
    <?php
    
    //get data
    $button = $_GET['submit'];
    $search = $_GET['search'];
    
    if (!$button)
    	echo "You didn't submit a keyword.";
    else
    {
    	if (strlen ($search)<=1)
    		echo "Search term too short.";
    	else
    	{
    		echo "You searched for <b>$search</b><hr size='1'>";
    	
    	//connect to database
    	 include('config.php');
    
    	 mysql_select_db("student_bay_co_", $connection);
    	
    	
    			
    			
    			//explode our search term
    			$search_exploded = explode(" ",$search);
    			
    			foreach($search_exploded as $search_each)
    			{
    				
    			//construct query
    				$x++;
    				if ($x==1)
    					$construct .= "keywords LIKE '%$search_each%'";
    				else
    					$construct .= " OR keywords LIKE '%$search_each%'";
    				
    			}
    			
    		
    		
    		//echo out construct
    		
    		$construct = "SELCECT * FROM products1 WHERE $construct";
    		$run = mysql_query($construct);
    		
    		$foundnum = mysql_num_rows($run) ;
    		
    		if ($foundnum==0)
    			echo "No results found.";
    		else
    		{
    			echo "echo $foundnum results found!<p>";
    			
    		}
    		
    	
    	}
    	
    }
    
    
    ?>

  2. #2
    Join Date
    Apr 2011
    Posts
    5
    PHP Code:
    <?php

    //get data
    $button $_GET['submit'];
    $search $_GET['search'];

    if (!
    $button)
        echo 
    "You didn't submit a keyword.";
    else
    {
        if (
    strlen ($search)<=1)
            echo 
    "Search term too short.";
        else
        {
            echo 
    "You searched for <b>$search</b><hr size='1'>";
        
        
    //connect to database
         
    include('config.php');

         
    mysql_select_db("student_bay_co_"$connection);
        
        
                
                
                
    //explode our search term
                
    $search_exploded explode(" ",$search);
                
                foreach(
    $search_exploded as $search_each)
                {
                    
                
    //construct query
                    
    $x++;
                    if (
    $x==1)
                        
    $construct .= "keywords LIKE '%$search_each%'";
                    else
                        
    $construct .= " OR keywords LIKE '%$search_each%'";
                    
                }
                
            
            
            
    //echo out construct
            //Change SELCECT to SELECT
            
    $construct "SELCECT * FROM products1 WHERE $construct";
            
    $run mysql_query($construct);
            
            
    $foundnum mysql_num_rows($run) ;
            
            if (
    $foundnum==0)
                echo 
    "No results found.";
            else
            {
                echo 
    "echo $foundnum results found!<p>";
                
            }
            
        
        }
        
    }


    ?>
    This is the problem, perhaps.
    PHP Code:
            $construct "SELCECT * FROM products1 WHERE $construct"
    Change to
    PHP Code:
            $construct "SELECT * FROM products1 WHERE $construct"

  3. #3
    Join Date
    Mar 2014
    Posts
    2

    resolved Dovrei avere trovato i tuoi errori

    $construct .= "LIKE '%$search_each%'";
    else
    $construct .= " OR LIKE '%$search_each%'";

    }



    //echo out construct

    $construct = "SELECT * FROM lavoro_hotel WHERE tipolavoro $construct";

  4. #4
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,176
    Nice job of resurrecting a 3-year-old thread.
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

  5. #5
    Join Date
    Mar 2014
    Posts
    2
    Thanks I didn't look at the date!

    Anyway is more than a mistake!

    If you need!

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles