Asked
Updated
Viewed
13.6k times

I have a database search question. I am useless with databases but I know how to search for one item at a time in my website's database; I just put in the item code (e.g. wk660) on the pd_code field line in the phpMyAdmin search page, but I don't know how to search for more than one item in a single search.

I want to search for several items in one search, using more than one item code at a time. I tried: wk660 OR wk30 OR wk483 to search for three at the same time for the field but it didn't find anything, although all three can be found if I do them one at a time.

I also tried separating them with AND and I tried enclosing the product codes in %%. None worked. My Google searches haven't helped me find how to do it. Can you tell me what I should put in to search for several items in one search, please?

There is a screenshot below of the phpMyAdmin search page to show what I mean. The line I put the item code (what I am searching) into is the pd_code field, you can see one item code in it in the picture:

phpMyAdmin Search Database Table

add a comment
0

2 Answers

  • Votes
  • Oldest
  • Latest
Answered
Updated

From the pulldown menu instead of choosing LIKE, choose REGEXP. Then for the value separate each thing you are searching for with a pipe symbol, which is |. So for instance you would put this for the value in the phpMyAdmin field box for pd_code:

wk660|wk30|wk483

Let me know if that does the trick 🙂

  • 0
    Yay! It found and displayed all three I put in. Thank you — cerio
add a comment
0
Answered
Updated

You're on the right track! phpMyAdmin allows searching for multiple items in a single search using the IN operator. Here's how to achieve what you want:

  1. Use the IN operator: Instead of OR or commas, separate your item codes with commas and enclose them within parentheses after IN. For example:
SELECT * FROM your_table WHERE pd_code IN ('wk660', 'wk30', 'wk483');

This query searches the your_table table for rows where the pd_code field value is either wk660, wk30, or wk483.

  1. Replace your_table: Make sure to replace your_table with the actual name of the table containing your product data (e.g., products).

  2. Consider Wildcards (Optional): If your item codes share a pattern (e.g., starting with "wk"), you can use wildcards with LIKE instead of IN. However, this might be less efficient for a large number of item codes.

Remember:

  • Escape special characters in your item codes if they contain things like apostrophes or backslashes. This helps prevent unexpected behavior in the query.
  • Make sure you're searching the correct field. In your example, it seems like pd_code is the field containing item codes.

By following these steps, you should be able to search for multiple items in your phpMyAdmin search and see results for all three product codes in one go.

add a comment
0