August 17, 200917 yr I have a form with some checkbox options, the options being in an array so that when the form is submitted the POST value for that array will be filled with the values from the checkboxes that were ticked. What I have done is pulled some content from a MySQL database, as I need to find out if any of the checkbox values are in a specific column in each row. The row field data would be something like this: 1_value 2_value What I need to do is split the n and the value and see if the checkbox values match any of the value results from the MySQL rows, if there's a match I want to be able to display information about that particular row to the user (i.e. in the form of search results). I have tried using in_array but I can't seem to get this working (probably me coding it wrong), does anyone have any ideas to this complicated scenario? lol Thanks Sam
August 17, 200917 yr Normally when you want to check something exist in a DB you want to let the database do the comparison instead of pulling lots of data and doing the work in PHP. I think I'd iterate over the checkbox array and extract the values you want to check for and build a SQL query.
August 17, 200917 yr Is this what you need Let us assume there is a form with three check boxes :Orange , Apple ,Banana .. and user is check Apple , Banana You now pass a query to MySQL Database and get a recordset. Now you need to find where the Apple and Banana is stored ( Row and column ) Please let me know , let us see if we can help you out Thanks MyDediServer Support Quality Servers and Server Support at a lesser cost
August 17, 200917 yr Author What complicates matters is that in the database, the values are in a serialized array, so the way I've done it is to pull the contents from the database, unserialize the field in each row, then extract the value from the id_value if you see what I mean. Otherwise I would have just checked in the database directly by doing the appropriate SELECT query.
August 17, 200917 yr Assuming you have the two arrays, one with the checkbox values and one with your DB data - then you can use array_intersect function. To process the raw arrays you can make a function for each that extracts the piece of data you want and run it through the array with the array_map function.
Create an account or sign in to comment