0

I have a table column where the value is an imploded value like this 5,9,1,6,4,8,2,24,14,3 now I want to run a query possibly like this SELECT * FROM table WHERE /* 1 is in array of (imploded_table_column)*/ Please I don't have a clue on how to run such query anyone with an idea or do I have to run the query in a long way like this:

$query = mysqli_query($con, "SELECT * FROM table");
$sql = mysqli_fetch_array($query);
$val = $sql['imploded_column'];
if(in_array('1', $val)){
    //run code here
}
2
  • Please add your problem statement in detail. Question is not clear. Commented May 16, 2016 at 5:38
  • 1
    use find_in_set. Commented May 16, 2016 at 5:40

2 Answers 2

4

i think you are looking for FIND_IN_SET function.

SELECT * FROM table WHERE FIND_IN_SET($yourValue, column-name)

try like below query in this FIND_IN_SET function 2 arguments first value which you want to find second your table column name.

More about FIND_IN_SET function read here

Sign up to request clarification or add additional context in comments.

Comments

1

You can use IN or find_in_set to solve this problem if you want this as mysql.

SELECT * FROM table WHERE 1 IN (imploded_column);
SELECT * FROM table WHERE find_in_set(1, imploded_column);

OR

You can use in_array if you want it as PHP solution. Just explode the $sql['imploded_column'] so it will be an array, after that you can use in_array.

$query = mysqli_query($con, "SELECT * FROM table");
$sql = mysqli_fetch_array($query);
$val = explode(",", $sql['imploded_column']);
if(in_array('1', $val)){
    //run code here
}

Comments

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.