473,795 Members | 2,410 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 3249
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.104 966$0Z5.88767@l akeread03>...

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.somefiel d = '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.goo gle.com...
"Phil Powell" <so*****@erols. com> wrote in message
news:<5Clnb.104 966$0Z5.88767@l akeread03>...

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.somefiel d = '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.somefiel d = '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.somefie ld" 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
12301
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 @patient TABLE
1
7852
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 from queries. Let me just add that Allen Browne excellent article about this subject may not apply to this scenario on an elementary level. (Here's the link to the article; Filter a Form on a Field in a Subform -...
8
6535
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 there are many examples. BUT, they fail sometimes. The techique is to pass the form's Me.filter as the "where condition" in a Docmd.openreport statement in code behind a "print button" on the form.
4
5140
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 Filter/Sort window: A window in which you can create a filter from scratch. You enter criteria expressions in the filter design grid to restrict the records in the open form or datasheet to a subset of records that meet the criteria.), you see the design...
6
17924
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 year & month When I try to place a date filter 'Between x And y ' on an expression field
1
4328
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 than 10 users. I'd like each user to see only some of the records in the database. So for example, if I have eight users in eight countries, I want each of them to only see information for their country. I was told that the easiest way to do...
11
6113
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 application controls allocation of revisions to aircraft maintenance manuals for an airline type operation. In the application there is a form loaded at start-up allowing the user/s to select the records that they are currently interested in from 4...
94
6931
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, Grade.Midpoint, Grade.Maximum, Job.EEOCategoryCode, EEOCategory.Desc, Job.EEOSubCategoryCode, EEOSubCategory.Desc FROM Grade RIGHT JOIN (EEOSubCategory RIGHT JOIN (EEOCategory RIGHT JOIN Job ON EEOCategory.Code = Job.EEOCategoryCode) ON...
1
3144
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. I’ve been successful in doing this for most of the buttons, but I’m having trouble reprogramming some Apply Filter buttons on one form and could use some help. So I have a Contacts List form that lists all of the division’s staff members...
0
9519
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10214
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10164
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10001
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7538
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6780
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5437
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5563
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4113
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 we have to send another system

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.