Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Old 01-01-2009, 08:40 PM Site Search Help
amw_drizz's Avatar
Ultra Talker

Posts: 340
Name: Jon
Location: New York
Trades: 0
I am trying to make a simple yet effective search function for my site, with both a basic and advanced search setup. The search engine does in theory work, it just outputs my entire table from the database on both occasions. I am using CodeIgniter since it has a lot of flexibility. And below you can find my code snippets.

Simple Search

PHP Code:
function doSearch()
    {
        
$search_String $this->input->post('Search');
        
$this->db->select('*')->from('content')->like('short_version'$search_String);
        
$query $this->db->get();
        if(
$query->num_rows() == 0){
            
$this->refinedSearch($search_String);
        }
        else{
            
$this->showResults($query->result_array());
        } 
    } 
Advanced Search
PHP Code:
    function advSearch(){
        
$search_string $this->input->post('keywords');
        
$where $this->input->post('catagory');
        
$refined $this->input->post('what');
        echo 
$where;
        
$this->db->select('*')->from('content')->where('cat_id',$where)->like($refined,$search_string);
        
$query $this->db->get();
        echo 
$query->num_rows();
        if(
$query->num_rows() == 0){
            
$data['content'] = "<h1>No Results Found!</h1>";
            
$data['content'] .= "<p> You searched for "$search_string ." has yeilded no results";
        }
        else{
            
$this->showResults($query->result_array());
        }
    } 
And my output is generic since they both use the same output page

PHP Code:
    private function showResults($array){
        
$result_loop['result_loop'] = $array;
        
$data['content'] = $this->parser->parse('dynamic/search/results',$result_loop,TRUE);
        
$this->parser->parse('dynamic/empty_page',$data);
        
    } 
So any Ideas on how to make this work correctly? In my head right now, it looks like when I do an advanced search in the title field with a keyword of dud, it should come up and say, Sorry No Search Results found. etc. But it shows all the contents of the table I am searching. And I have 7 records in it right now with no Dud in the title box. Even when I try Hosting, which is 1 row in my table I still get all 7 results.
__________________
AMW_Drizz
Dev Machine:: Apache 2.2.6 PHP 5.2.6 MySQL 5.1
amw_drizz is offline
Reply With Quote
View Public Profile Visit amw_drizz's homepage!
 
 
Register now for full access!
Reply     « Reply to Site Search Help
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.80939 seconds with 12 queries