Skip to content
View in the app

A better way to browse. Learn more.

Web Designer Forum

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

PHP - searching array values with values from another array?

Featured Replies

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

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.

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

  • 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.

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.

  • Author

I'm not sure I follow...?

  • Author

Managed to sort it out myself in the end, thanks anyway.

Create an account or sign in to comment

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.