Welcome Guest, Not a member yet? Register   Sign In
PHP search with spaces
#11

[eluser]Kraig[/eluser]
Would I have to explode the $keys first before I send it into that foreach?
#12

[eluser]Kraig[/eluser]
I try the following the code and I get no results when there should be. The commented query works.

Code:
$key = trim($key);
  $keys = explode(" ", $key);
  
  $this->db->select('*');
  $this->db->from('upload');
  foreach($keys as $piece){
     $this->db->or_like('name', $piece);
  }
  $this->db->limit($start, $limit);
  $query = $this->db->get();
  //$query = $this->db->query("SELECT * FROM upload WHERE name LIKE '%".$key."%' LIMIT $start, $limit");
#13

[eluser]Kraig[/eluser]
Anyone looking for the answer I did this:

Code:
foreach($keys as $piece){
   $query = $this->db->query("SELECT * FROM upload WHERE name LIKE '%".$piece."%' LIMIT $start, $limit");
}
#14

[eluser]DarkManX[/eluser]
just echo the query-string by $this->db->last_query() to see what you constructed and whats wrong. there might be a problem with starting by or_link(). the query !maybe look like this:

Code:
SELECT * FROM upload WHERE OR LIKE '%key%' OR LIKE '%key2%'

Im to lazy to check it myself right now
#15

[eluser]theprodigy[/eluser]
[quote author="Kraig" date="1345860880"]I try the following the code and I get no results when there should be. The commented query works.

Code:
$key = trim($key);
  $keys = explode(" ", $key);
  
  $this->db->select('*');
  $this->db->from('upload');
  foreach($keys as $piece){
     $this->db->or_like('name', $piece);
  }
  $this->db->limit($start, $limit);
  $query = $this->db->get();
  //$query = $this->db->query("SELECT * FROM upload WHERE name LIKE '%".$key."%' LIMIT $start, $limit");
[/quote]

The only things I would do to this is:
1. No need for the select('*'). If you don't set the select, CI does this automatically.
2. Where are you setting your $start and $limit variables?




Theme © iAndrew 2016 - Forum software by © MyBB