0

i want to search data in an array .How can i search using mysql select command. i wrote the query as

$this->db->query("SELECT * FROM client_details WHERE dob IN ({implode(',', $data})");

$data is an array of dates .Please Help me for solving this..

6
  • And what is the error message you get? Commented Mar 18, 2015 at 10:23
  • so whats the problem ??? where you stuck ???? Commented Mar 18, 2015 at 10:27
  • Error Number: 1064 Erreur de syntaxe près de '})' à la ligne 1 SELECT * FROM client_details WHERE dob IN ({implode(',', 03/03/2015}) error showing like this Commented Mar 18, 2015 at 10:27
  • You have to properly escape the string, use mysql_real_escape_string Commented Mar 18, 2015 at 10:29
  • how can i use mysql_real_escape_string Commented Mar 18, 2015 at 10:41

2 Answers 2

2

try with

$data =array('0'=>'2015-01-23','1'=>'2015-01-22','2'=>'2015-01-21');
$tmp = implode('","', $data);
$tmp ='"'.$tmp.'"';
$sql= 'SELECT * FROM client_details WHERE dob IN ('.$tmp.')';
echo $sql;
$this->db->query($sql);
Sign up to request clarification or add additional context in comments.

Comments

0

You can do something like this:

Option 1

$tmp = implode(',', $data);
$this->db->query("SELECT * FROM client_details WHERE dob IN ($tmp)");

Option 2

$this->db->query("SELECT * FROM client_details WHERE dob IN (".implode(',', $data).")");

Also, there is a mistake in your bracket formation.

It should be dob IN ({implode(',', $data)}"); [Curly braces should close after the closing parenthesis].

17 Comments

Severity: Warning Message: implode(): Invalid arguments passed ..showing this error
Error Number: 1064 Erreur de syntaxe près de ')' à la ligne 1 SELECT * FROM client_details WHERE dob IN () and also this error showing
03/03/201504/13/201505/11/201506/08/201509/04/201512/06/201503/08/201606/09/201609/10/201603/01/201703/01/201902/27/202702/29/202003/18/201504/28/201505/26/201506/23/201509/19/201512/21/2
$data values are this
Try removing { } from your initial query. And what is the datatype of your dob column?
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.