1

I need to check if the array stored data matches with the data present in the database. Meaning that, user will select check box data 1,4,5 which will be stored as $data[]. In database there is a table with a column ID which will have 1, 2, 3, 4, 5. Every time user selects different check box, which will be stored in $data. I want to check those values with the database ID and i want to get only those values which is stored in-front of that ID in other column called 'value'

Example: if $data has value 3, 4, then it should get the value from the database only for 4 and 5.

I am not getting how to do this comparison and get the value.

$query = "select values from customer where bname = '".$_POST['bname']."' ";

$update = DB_query($query,$db);
while($row = DB_fetch_array($update))
{
    $array=explode(',',$row["values"]);
}
5
  • 2
    can you paste your code here? Commented Aug 29, 2013 at 6:22
  • 1
    Use "where in" clause in sql to select all selected value. Commented Aug 29, 2013 at 6:24
  • 1
    @senthilbp: I have posted my code Commented Aug 29, 2013 at 6:31
  • 1
    Try array_diff() .. hope it helps!!! Commented Aug 29, 2013 at 6:38
  • 1
    @sentilbp: thanks for your time. i used in_array() as suggested by Avin Varghese , it worked fine!. Commented Aug 29, 2013 at 7:14

1 Answer 1

1

Use php array_diff(); OR in_array(); to compare array with your MySQL column.

  $query = "select values from customer where bname = '".$_POST['bname']."' ";

$update = DB_query($query,$db);
while($row = DB_fetch_array($update))
{
    $array=explode(',',$row["values"]);
}

    if (in_array("one", $array)) {
        echo "one Found";
    }
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you very much Avin Varghese , It worked as i wanted!. Thanks a ton

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.