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 7521805
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T02:20:09+00:00 2026-05-30T02:20:09+00:00

I am having a bit of a problem running a select query on a

  • 0

I am having a bit of a problem running a select query on a database. Some of the data is held as a list of comma separated values, an example:

Table: example_tbl
| Id | People | Children |
| 1  | 1,2,3  |  8,10,3  |
| 2  | 7,6,12 |  18,19,2 |

And an example of the kind of thing I am trying to run:

<?php
    include 'class.php';
    $selection = 1;
    $db = new DbClass;
    $tbl_name = 'example_tbl';
    $sql = "SELECT * FROM $tbl_name WHERE ".$selection." IN People";
    $result = $db->query($sql);
    $print_r($result);
?>

The script above should return row 1 after finding a ‘1’ in the People column but clearly I have mucked it up.

The issue I am having is that I think I have the IN statement backwards, i.e. I THINK this method would be to select values if $selection was a comma separated (imploded) list, rather than the way round I am trying to use it.

I don’t know if it’s too important about what I am sending and receiving from the db class above, but if you wanted to know, it’s just a simple script that runs all relevant bits and returns an array of the result. at the moment it’s returning nothing because it’s not finding a match

Thanks in advance for anything you can tell me.

Cheers
-Dave

  • 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-05-30T02:20:10+00:00Added an answer on May 30, 2026 at 2:20 am

    Why do people insist on this insane habit of comma-separated data values in a column rather than properly normalising their database design. It always leads to problems.

    SELECT * 
      FROM $tbl_name 
     WHERE CONCAT(',',People,',') LIKE '%,".$selection.",%'";
    

    or

    SELECT * 
      FROM $tbl_name 
     WHERE FIND_IN_SET(".$selection.",People);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm having a bit of a problem deciding how to store some data. To
I'm having a bit of a problem with moving specific data from one server
Having problem with this bit of code qith jQuery. it should pick the values
Having a bit of a problem running multiple workers. When creating workers with rake
Having a bit of a problem, Due to the source-control set-up we use, each
Having a bit of a problem creating an instance of an object. Bear in
I am having a bit of a problem. I get a RAW char* buffer
I'm having a bit of a problem. I have a datatable in the parent
I'm having a bit of a problem with converting the result of a MySQL
I'm having a bit of a problem here. We have 2 urls let me

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.