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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T21:56:03+00:00 2026-05-22T21:56:03+00:00

I do a database call to list all the categories that belong to a

  • 0

I do a database call to list all the “categories” that belong to a user. This returns to me an array, with sub-arrays with specific data on each category.

How do I pick out the category IDs from these, and combine them to form a new query that grabs all the posts in these categories?


Tables: “assignments” and “classes”.

Assigments: assignmentid, classid, …
Classes: classname, userid, …

Here’s the code I’m using.

$query = dbquery("SELECT classid, classinfo FROM classes WHERE userid = 1");

This returns to me an array with subarrays:

Array ( 
[0] => Array ( [classid] => 2 [classinfo] => classinfo )
[1] => Array ( [classid] => 3 [classinfo] => classinfo ) 
...

How would I extract out all the classids, and then list them as “2 OR 3 OR …” for use in another MySQL query?

  • 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-22T21:56:04+00:00Added an answer on May 22, 2026 at 9:56 pm

    You don’t really have to do that (get the classids in PHP and then send another query). You could simply use the query you have with something like:

    SELECT assignments.assignmentid      
         , assignments.classid
         , assignments.otherfield
    FROM assignments
    WHERE assignments.classid IN 
      ( SELECT classid, classinfo
        FROM classes
        WHERE userid = 1
      )
    

    or

    SELECT assignments.assignmentid      --- or whatever fields you want
         , assignments.classid           --- from table assignments
         , classes.classinfo           --- or table classes
    FROM assignments
      JOIN classes
        ON assignments.classid = classes.classid
    WHERE classes.userid = 1  
    

    Both these queries will show almost same results (if you remove the classes.classinfo from the second query, the results will be identical). That is, all assignments data that are related to a class with userid = 1.


    There are numerous SQL tutorials on the web. You can try for example: w3schools.com

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

Sidebar

Related Questions

I'm trying to get my head round this mind boggling stuff they call Database
I got two tables in my database: user and call. User exists of 3
In this stored procedure I want to get list of all the tables of
I have a database table with a list of products (clothing). The products belong
Say you have a ServiceCall database table that records down all the service calls
Ok, so in our employee database, we keep a list of all employees and
I am adding membership-related schemas to an existing database (lets call it myDatabase) following
I have a database table named call with columns call_time, location, emergency_type and there
My asp.net application is not using formsauthentication. Instead we make a call to database,
Can I call a stored procedure in Oracle via a database link? The database

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.