1

I am developing an application using Codeigniter 2.1.0 and MySQL. In my application I have a search feature. Here is code for search.

function get_results($query, $post_per_page,$current_page) {

    $offset=($current_page-1)*$post_per_page;
    if($current_page==1) {
        $offset = 0;
    }

    $sql = "SELECT * FROM data WHERE  MATCH ( source ) AGAINST (?) LIMIT ?,?"; 
    $query = $this->db->query($sql, array($query, $offset, $post_per_page));

    return $query->result_array();
}

Sample paragraph is

CodeIgniter User Guide Version 2.1.0 Getting Started With CodeIgniter Any software application requires some effort to learn. We've done our best to minimize the learning curve while making the process as enjoyable as possible. The first step is to install CodeIgniter, then read all the topics in the Introduction section of the Table of Contents. Next, read each of the General Topics pages in order. Each topic builds on the previous one, and includes code examples that you are encouraged to try. Once you understand the basics you''ll be ready to explore the Class Reference and Helper Reference pages to learn to utilize the native libraries and helper files.

I perform a query "codeigniter" and "User Guide" But this function returns 0 results on both queries. However words "codeigniter" and "User Guide" are exists in the sample paragraph. Please suggest some helpful code or ideas for this problem

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Seek Php
  • 163
  • 2
  • 3
  • 12
  • Have you tried plugging sample values into the query and sending it directly to MySQL (via the command line, or phpmyadmin if you have it)? That should narrow down the potential sources of the problem. – octern Mar 29 '12 at 02:54
  • did you try exact case for search? Ex: `CodeIgniter` and not `codeigniter` – rs. Mar 29 '12 at 02:57
  • @octern Yes I've tried query in PHPmyAdmin and it returns "MySQL returned an empty result set (i.e. zero rows)." – Seek Php Mar 29 '12 at 02:59
  • In that case, the PHP code you posted here is definitely not the source of the problem (or at least, not the only source of the problem). Now you need to focus on your tables and figuring out why the query doesn't work the way you think it should. (unfortunately I have no immediate ideas about that.) – octern Mar 29 '12 at 03:02
  • @octern but some quires return results like "learn codeigniter" – Seek Php Mar 29 '12 at 03:08
  • @rs. Yes I've tried exact search. But doesn't work. Some keywords return results like "Learn codeigniter" – Seek Php Mar 29 '12 at 03:11
  • Maybe you don't have enough rows. See http://stackoverflow.com/questions/3439416/fulltext-search-in-mysql-does-not-return-any-rows – Phil Mar 29 '12 at 03:21
  • @Phil I've about 600 rows in my mysql database – Seek Php Mar 29 '12 at 09:11
  • Is your database MyISAM or InnoDB? How are your tables collated? – Seabass Mar 29 '12 at 17:33
  • @Zenbait my database in MyISAM – Seek Php Mar 31 '12 at 07:48
  • Use InnoDB for all of your tables and ensure that they are all collated the same, especially if you're doing relational cross-table references and searching. I'm not sure about your application, but utf8_unicode_ci is usually a good way to go. – Seabass Apr 02 '12 at 18:17

0 Answers0