954,600 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Querying within the results of a previous query?

I'm trying to figure out if this is possible, and cannot find any information about it.

Specifically what I want to do, for example, is allow a web-based user to search for a particular value in one field the first time around. If that returns an overwhelming number of results, I'd like for them to be able to search from within the results of the first query.

I suppose I could have the prior query statement POSTed with the results and nest a bunch of statements, but this seems like it could get really ugly in a hurry. :eek:

Any ideas?

Serp
Newbie Poster
2 posts since Mar 2005
Reputation Points: 10
Solved Threads: 0
 

I believe within MySQL 4.1 it supports subqueries.. if thats what your looking for.

Zachery
The Geek Father
Team Colleague
894 posts since Nov 2003
Reputation Points: 96
Solved Threads: 21
 

Hmm, no, a subquery is just a one-time thing, too. I'm talking about subsequent calls to the mysql_query() function.

For example, let's say I have a database with tons of records. Here's the first query, which returns thousands of results:

$query="SELECT * FROM sometable WHERE [some condition]";
$result=mysql_query($query);

[at this point, code execution has stopped and the user is on a different page. The user decides to narrow the search, so I'd like to know if there is something akin to the following]

$query2="SELECT * FROM $result where [condition2]";
$result2=mysql_query($query2);

Where $result is a pointer to a table in memory containing the rows that were pulled in the first query.

Serp
Newbie Poster
2 posts since Mar 2005
Reputation Points: 10
Solved Threads: 0
 

Mmmm... maybe creating a temporary table with the results of the first query but that will kill performance. In my opinion it is better to create a seach form that "remembers" the values and then the client can always have that reference and change the options to narrow the search.

RamiroS
Junior Poster in Training
57 posts since Mar 2005
Reputation Points: 10
Solved Threads: 2
 

My site is a community (neighborhood) site and there are all manner of products available at shops. This is my category area.

I do this:

super category >> many to many >> category >> many to many >> shop.

I start with a super category (say dining). Click it and the many to many has dining pointing to Chinese, Italian, Catering and so on. This is displayed. Then the viewer selects the specific category and then the full select statement is put into effect.

Hope this helps.

edshuck
Newbie Poster
1 post since Mar 2005
Reputation Points: 10
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You