Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9078191
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T19:33:32+00:00 2026-06-16T19:33:32+00:00

I am fairly new with PDO but i have come across something which probably

  • 0

I am fairly new with PDO but i have come across something which probably has an easy answer.

I have an array of category numbers to which i need to search through a mysql database to find all items with the matching category number.

I know i have connected to DB correctly as i am receiving the category array from a different query.

$category = Array ( [0] => 3259 [1] => 3617 [2] => 3257 [3] => 3258 [4] => 3450 [5] => 3452 [6] => 3478 [7] => 3479 [8] => 3480 [9] => 3448 [10] => 3449 [11] => 3451 [12] => 3456 [13] => 3454 [14] => 3455 [15] => 3459 [16] => 3460 [17] => 3458 [18] => 3453 [19] => 3461 [20] => 3462 [21] => 3457 [22] => 3463 [23] => 3447 ) 

now i need to go through the item database to check for matching categories.
Each item can have multiple categories, each category has 4 digits.
multiple categories are seperate with a =

$categoryResults = $conn->prepare('SELECT * FROM items WHERE category like :cats ORDER BY promotions,price ASC');
$categoryResults->execute(array(':cats' => '%'.$category.'%'));
$categoryNumber = $categoryResults->rowCount();

This is where i seem to have gone wrong. With the mysql request i would have built it up manually using a loop through the array to get me a long sql query :

'Select * From items WHERE category like '%3259%' OR WHERE category LIKE '%3617%'........etc

But i am sure this is one of the advantages of using PDO.
Just to add to it i need the results to be unique.
If item 97 is in category 3259 and category 3617 i only want to get the result once.

Thanks in advance.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T19:33:33+00:00Added an answer on June 16, 2026 at 7:33 pm

    I find it stange that you are looking for numbers with a LIKE statement. Isnt category just the ID of the category or how is it stored? If category is CSV list, I advise you to alter it to make use of a seperate table for many to many connections.

    If it’s already a numeric value, just use the IN statement

    $categoryResults = $conn->prepare('SELECT * FROM items WHERE category IN (:cats) ORDER BY promotions,price ASC');
    $categoryResults->execute(array(':cats' => implode(',', $category));
    $categoryNumber = $categoryResults->rowCount();
    

    Update
    Or even better, check out this question which is the same.

    Can I bind an array to an IN() condition?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am fairly new to php and mysql but I have created a small
fairly new Android developer here. I've come across a strange problem that I'm not
Fairly new to Jquery here.... but one thing I have been told and being
Fairly new to asp.net Mvc and jquery. Have the following code working fine, but
I fairly new to JQuery and perhaps trying to achieve something that might be
I am new to fairly new to AS3 and I have found myself needing
I'm fairly new to C++ standard library and have been using standard library lists
Fairly new to jquery so I might be making a simple mistake but I
Fairly new to Google Maps API. I've got an array of data that I
Fairly new to socket programming, but I've been assigned with a whopper of project.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.