944,008 Members | Top Members by Rank

Ad:
  • MySQL Discussion Thread
  • Unsolved
  • Views: 5655
  • MySQL RSS
Mar 8th, 2005
0

Querying within the results of a previous query?

Expand Post »
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?
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Serp is offline Offline
2 posts
since Mar 2005
Mar 8th, 2005
0

Re: Querying within the results of a previous query?

I believe within MySQL 4.1 it supports subqueries.. if thats what your looking for.
Team Colleague
Reputation Points: 96
Solved Threads: 21
The Geek Father
Zachery is offline Offline
781 posts
since Nov 2003
Mar 9th, 2005
0

Re: Querying within the results of a previous query?

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.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Serp is offline Offline
2 posts
since Mar 2005
Mar 10th, 2005
0

Re: Querying within the results of a previous query?

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.
Reputation Points: 10
Solved Threads: 2
Junior Poster in Training
RamiroS is offline Offline
57 posts
since Mar 2005
Mar 12th, 2005
0

Re: Querying within the results of a previous query?

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.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
edshuck is offline Offline
1 posts
since Mar 2005

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in MySQL Forum Timeline: MySQL. Very much a beginner
Next Thread in MySQL Forum Timeline: Changing Websites





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC