473,499 Members | 1,525 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to filter queries using PHP

http://www.php.net/array_filter

I went there at first for my information on filtering mySQL query results
using PHP, to no
avail.

This is more of a Vignette construct (my native environment) so bear with
me. I decided the
easiest course of action to tackle a perplexing problem involving two
queries and having to
display them in a certain customized manner:

Query 1
1 - 1 billion rows (who knows!), with field 'iref'

Query 2
1 - [infinity] rows (who knows!), with field 'iref'

the queries are based upon the concept that Query1.iref = Query2.iref and
that Query1 has
a one-to-many relationship with Query2, based on iref.

I am tasked with displaying in a report one row from Query1 and all
subsequent rows from
Query2 (which are "grouped" by iref for ease sake) where Query1.iref =
Query2.iref.

Problem is, I am having to use embedded WHILE loops to parse through the
queries and produce
my results, which is a horrific performance problem and the client is
way-not-happy about
that. Furthermore, I would have to do individual Query2 queries solely
based upon iref, which
means countless hundreds of db entry calls on a single query, still having
to parse inside
embedded WHILE loops. WORSE performance hog.

So I remember from my Vignette days a TCL proc written by VPS professionals
called FILTER
which would filter through the query resultset and only produce the
rows/cols where a col
field value = $fieldValue and that would make life a breeze.

But PHP alas has nothing like that, unless someone else can point me to a
direction where
I can find just that. I tried writing my own and I don't even know the
logic as to how to
imagine how to create my own FILTER.

Thanx
Phil
Jul 17 '05 #1
4 3234
Hi Phil!

On Mon, 27 Oct 2003 22:42:12 -0500, "Phil Powell" <so*****@erols.com>
wrote:
http://www.php.net/array_filter

I went there at first for my information on filtering mySQL query results
using PHP, to no
avail.
do it in the database.
This is more of a Vignette construct (my native environment) so bear with
me. I decided the
easiest course of action to tackle a perplexing problem involving two
queries and having to
display them in a certain customized manner:

Query 1
1 - 1 billion rows (who knows!), with field 'iref'

Query 2
1 - [infinity] rows (who knows!), with field 'iref'

the queries are based upon the concept that Query1.iref = Query2.iref and
that Query1 has
a one-to-many relationship with Query2, based on iref.
A so-called "inner join"

I am tasked with displaying in a report one row from Query1 and all
subsequent rows from
Query2 (which are "grouped" by iref for ease sake) where Query1.iref =
Query2.iref.

Problem is, I am having to use embedded WHILE loops to parse through the
queries and produce
my results, which is a horrific performance problem and the client is
way-not-happy about
that. Furthermore, I would have to do individual Query2 queries solely
based upon iref, which
means countless hundreds of db entry calls on a single query, still having
to parse inside
embedded WHILE loops. WORSE performance hog.

So I remember from my Vignette days a TCL proc written by VPS professionals
called FILTER
which would filter through the query resultset and only produce the
rows/cols where a col
field value = $fieldValue and that would make life a breeze.
called a WHERE statement

But PHP alas has nothing like that, unless someone else can point me to a
direction where
I can find just that. I tried writing my own and I don't even know the
logic as to how to
imagine how to create my own FILTER.
Thats because PHP is more a web based swiss army knife and does not
integrate a database environment from start (by hiding this dependency
from you)
Look up

-select statement
- inner join
- where

on www.mysql.com

and look up in google how to display MySQL queries in tables in PHP.

Mosty probably you'll also need

- limit
- order by
HTH, Jochen

Thanx
Phil


--
Jochen Daum - CANS Ltd.
PHP DB Edit Toolkit -- PHP scripts for building
database editing interfaces.
http://sourceforge.net/projects/phpdbedittk/
Jul 17 '05 #2
"Phil Powell" <so*****@erols.com> wrote in message
news:<5Clnb.104966$0Z5.88767@lakeread03>...

I decided the easiest course of action to tackle a perplexing
problem involving two queries and having to display them in
a certain customized manner:

Query 1
1 - 1 billion rows (who knows!), with field 'iref'

Query 2
1 - [infinity] rows (who knows!), with field 'iref'

the queries are based upon the concept that Query1.iref = Query2.iref
and that Query1 has a one-to-many relationship with Query2, based
on iref.


Note that you are needlessly complicating your life. Reduce
two queries to one. Then there's no need to filter anything;
you will get right to the dataset you need. Something like:

SELECT table1.this, table2.that
FROM table1 LEFT JOIN table2 ON table1.iref = table2.iref
WHERE table1.somefield = 'SomeValue';

Cheers,
NC
Jul 17 '05 #3
I cannot honestly think of simple solutions to anything. I'm dead serious,
I never saw that solution at all!

Phil

"Nikolai Chuvakhin" <nc@iname.com> wrote in message
news:32**************************@posting.google.c om...
"Phil Powell" <so*****@erols.com> wrote in message
news:<5Clnb.104966$0Z5.88767@lakeread03>...

I decided the easiest course of action to tackle a perplexing
problem involving two queries and having to display them in
a certain customized manner:

Query 1
1 - 1 billion rows (who knows!), with field 'iref'

Query 2
1 - [infinity] rows (who knows!), with field 'iref'

the queries are based upon the concept that Query1.iref = Query2.iref
and that Query1 has a one-to-many relationship with Query2, based
on iref.


Note that you are needlessly complicating your life. Reduce
two queries to one. Then there's no need to filter anything;
you will get right to the dataset you need. Something like:

SELECT table1.this, table2.that
FROM table1 LEFT JOIN table2 ON table1.iref = table2.iref
WHERE table1.somefield = 'SomeValue';

Cheers,
NC

Jul 17 '05 #4
Phil Powell wrote:
I cannot honestly think of simple solutions to anything. I'm dead serious,
I never saw that solution at all!


Phil, that is a "shocker" ;)
.... we all have 'em ...
SELECT table1.this, table2.that
FROM table1 LEFT JOIN table2 ON table1.iref = table2.iref
WHERE table1.somefield = 'SomeValue';


If this query is heavily used or has a lot of data, make sure you create
indexes on "both" columns in the join (one from each table). If you
created one as the primary key, then it should already have a UNIQUE
index automatically created for it. You also want to index the column
you're filtering on ie. "table1.somefield" as per above example. If you
plan on using an ORDER BY clause, then create an index that spans the
columns in the order-by list (if they are from the same table).

Too many indexes impact on your INSERT performance, but I'm guessing
that you are doing a lot of reading. Database optimisation is probably a
black art, I don't know that much about it, but I think the above should
be good advice. Too many indexes are bad for other reasons to but I
forgotten them presently :)
Any experts out there with some DB optimisation advice???

good luck Phil.

Jul 17 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
12283
by: Chris Geihsler | last post by:
I have a set of udf's dealing that return a one column table of values parsed from a comma delimeted string. For example: CREATE FUNCTION . ( @patient_list varchar(2000) ) RETURNS...
1
7829
by: Robert Neville | last post by:
I would like to add filter functionality to my database whether through the Main form or the subform. This question may be rudimentary, yet I have not less experience with filtering data outside...
8
6510
by: dick | last post by:
I am just trying to print/report the results of a "filter by selection" which is done by right-clicking a form, filling in values, and "applying the filter." I have searched the newsgroups, and...
4
5116
by: Nhmiller | last post by:
This is directly from Access' Help: "About designing a query When you open a query in Design view, or open a form, report, or datasheet and show the Advanced Filter/Sort window (Advanced...
6
17888
by: Tony Miller | last post by:
All I have an aggregate query using the function Month & Year on a datereceived field ie: TheYear: Year() TheMonth: Month() These are the group by fields to give me a Count on another field by...
1
4295
by: Julia | last post by:
Hello there. I have a question somewhat related to this topic, and I don't know where else to go. I hope somebody can help. I've created a database in access, that I'd like to share with less...
11
6066
by: Bob | last post by:
I am in the process of upgrading an Access database to SQL Server (and climbing that learning curve!). The wizard happily upgraded all the tables and I can link to them OK using ODBC. The...
94
6825
by: mlcampeau | last post by:
I have a report (JobVacanciesOnly) that has a subreport (JobVacanciesOnlySR) that are based on two separate queries. MY - JobVacancyJobs SELECT Job.Code, Job.Title, Job.Grade, Grade.Minimum,...
1
3117
by: eHaak | last post by:
A couple years ago, I built a database in MS Access 2003. I built the form using macros in some of the command buttons, and now I’m trying to eliminate the macros and just use visual basic code. ...
0
7130
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7007
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7220
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
7386
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5468
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
3098
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3090
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1427
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
295
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.