NYCPHP Meetup

NYPHP.org

[nycphp-talk] comparing arrays to build query?

Kristina Anderson ka at kacomputerconsulting.com
Sun Jun 8 14:25:23 EDT 2008


that's really really close to what I need ... except that I first have 
to test for if Jobs.remzip is empty and if so, query on Employers.zip 
instead.

This sounds like it might be a task for that Coalesce function we were 
discussing a few months back?

As long as the array implodes before the client implodes, this might 
work :) Thanks Mark



-- Kristina

> So you have an array of zips, like array(11201, 11206, 11301), 
right?  
> and you need to find all the jobs within that array of zips?
> 
> If so your query would look something like this:
> 
> mysql_query('SELECT * FROM Providers INNER JOIN Employers ON 
Jobs.empid = 
> Employers.EmpID WHERE Jobs.zip IN (' . implode(',', $aZips) . ')');
> 
> Which becomes 
> SELECT * FROM Providers INNER JOIN Employers ON Jobs.empid = 
> Employers.EmpID WHERE Jobs.zip IN (11201,11206,11301)
> 
> Not sure if that's what you're looking for.
> 
> Mark
> 
> 
> Kristina Anderson wrote:
> > OK, this really has me flummoxed.  I'm not sure if I'm going about 
this 
> > the right way.
> >
> > I have three tables, an Employer table, a Provider table and a Jobs 
> > table.  Each Provider (worker) has up to nine zip codes and a 
possible 
> > metro area which contains all the zip codes in their city which is 
> > their "service area".
> >
> > When they log on, I need to display only the Jobs in any of their 
zip 
> > codes. 
> >
> > In the Jobs table, there is a remote zip field (remzip) and if that 
has 
> > a value, that is the zip where the job is, otherwise we use the zip 
> > field in the Employers table.
> >
> > I've built two arrays one by 
> > "SELECT * FROM Providers INNER JOIN Employers ON Jobs.empid = 
> > Employers.EmpID ";
> >
> > which gives me both the remzip and zip fields and the jobid field.
> >
> > And one by querying the database for all the zips in the service 
area 
> > of that particular Provider and dumping them all into an array.
> >
> > So now I have these two arrays I can compare...is there an easier 
way 
> > to do this or ... ?
> >
> > I need to compare these two arrays and if any value from array 2 is 
in 
> > array 1, pull out the entire row by jobid from the database and 
display 
> > it.
> >
> > Thanks in advance,
> > ---- Kristina 
> > _______________________________________________
> > New York PHP Community Talk Mailing List
> > http://lists.nyphp.org/mailman/listinfo/talk
> >
> > NYPHPCon 2006 Presentations Online
> > http://www.nyphpcon.com
> >
> > Show Your Participation in New York PHP
> > http://www.nyphp.org/show_participation.php
> >
> >   
> 
> _______________________________________________
> New York PHP Community Talk Mailing List
> http://lists.nyphp.org/mailman/listinfo/talk
> 
> NYPHPCon 2006 Presentations Online
> http://www.nyphpcon.com
> 
> Show Your Participation in New York PHP
> http://www.nyphp.org/show_participation.php
> 
> 




More information about the talk mailing list