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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T11:01:11+00:00 2026-05-24T11:01:11+00:00

I was recently trying to do a project*, which caused me to ask this

  • 0

I was recently trying to do a project*, which caused me to ask this question. Although since then I’ve found an alternative solution, I am still curious if what I envisioned doing is, in any way, possible.

Essentially, I am wondering if there is anyway to perform a MySQL query on a MySQL query result in php. For example:

$result = mysql_query("SELECT * FROM foo WHERE bar=".$barValue);

AND THEN, be able to perform multiple queries on $result:

$newResult = mysql_query("SELECT * FROM $result WHERE otherBar=".$barValue);

OR

$otherNewResult = mysql_query("SELECT * FROM $result WHERE otherOtherBar=".$barValue." ORDER BY foobar ASC");

AND so on and so forth…

I realize that I could append the original query with my new WHERE statements and ORDER BYs, but that causes my to query the database unnecessarily and it prevents me from writing more objected oriented code (because I can’t pass around a result to be queried, but rather have to requery the database in every function…)

Any advice, pieces of code, frameworks, or ramblings appreciated.

*BTW, my project was having to query a large database of people for people born in certain age groups and then query those age groups for different demographics.

Edit

No, writing a custom function to query the database is not worth the object-orientation (and modifiability) it would give me

  • 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-24T11:01:13+00:00Added an answer on May 24, 2026 at 11:01 am

    You could do a nested query in the same SQL query and keep PHP out of it:

    'SELECT * FROM (SELECT * FROM foo WHERE bar="something") AS q1 WHERE q1.bar2 = "something else"'
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've become very addicted to Project Euler recently and am trying to do this
recently I downloaded this open source project and I am trying to compile it.
I have recently being trying to create a project which has several levels of
Recently, I'm trying to write a simple OS. This is a big project. when
I recently came across this in some code - basically someone trying to create
I recently started a new project and I'm trying to keep my instance variables
Recently I've been revisiting an old project, which I last worked on about two
I've recently inherited a project primarily done in C++, so this is my first
I've recently started a Rails 3 project which I checked out from github. The
A question here, I recently installed a software on my computer which comes with

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.