Forums

PHP

This topic is locked

filtering with multiple fields

Posted 30 Mar 2007 00:40:07
1
has voted
30 Mar 2007 00:40:07 Kiel Fellow posted:
I Have problem where I need to filter from two fields my current recordset is:

SELECT nc_report.Emp_No, nc_report.NC_Num, nc_report.NC_Description, root_cause.Person_Responsible, root_cause.PCD_day, root_cause.PCD_month, root_cause.PCD_year, root_cause.ACD_day,root_cause.ACD_month, root_cause.ACD_year,root_cause.Solution_Description, verification.VCD_month
FROM nc_report LEFT JOIN root_cause on root_cause.NC_No = nc_report.NC_Num LEFT JOIN verification on verification.NC_No = nc_report.NC_Num
WHERE nc_report.Emp_No = colname
ORDER BY nc_report.NC_Num desc

it is a reporting site where a user logs on and makes reports. this is from the worklist page where it show the employee all the reports that they have done.
but at the moment it only shows reports that the employee have done themselves I also want it to display the records where they are the supervisor or the person responsible
so I really need another WHERE like
WHERE root_cause.Person_Responsible = colname

Replies

Replied 30 Mar 2007 01:00:29
30 Mar 2007 01:00:29 Alan C replied:
"SELECT p_id, p_name, p_address_1, p_address_2, p_town, p_postcode, p_admin_hold, p_entry_type, p_image_path, p_min_cost, p_max_cost, p_stars, p_diamonds, p_tel, p_description, p_www, p_email FROM properties WHERE p_admin_hold='normal' AND p_min_cost>0 AND p_max_cost>0 AND p_rooms >0 ORDER BY p_entry_type DESC, p_created DESC"

this query checks 4 fields as part of the SELECT I think you can put as many in as you like.

If you have phpmyadmin you can go to the sql page and test out your queries to check that they give the right results before you put them into code.
Replied 30 Mar 2007 01:11:12
30 Mar 2007 01:11:12 Kiel Fellow replied:
I just tried to do it by using AND but it only gives me the records that match both WHERE statements I want to get all the records the user has made as well as all the records that relate to that user
Replied 30 Mar 2007 17:53:34
30 Mar 2007 17:53:34 Alan C replied:
You can do a combination of AND plus OR and include brackets to force the order or evaluation

something like this perhaps . . .

<pre id=code><font face=courier size=2 id=code> $query_rsEvents = "SELECT * FROM events INNER JOIN cities ON events.event_city = cities.city_number WHERE approved = 'yes' AND start_activity &gt;= now() AND start_activity &lt;= ADDDATE(NOW(), INTERVAL 90 DAY) AND (event_type = 'Regional' OR (event_type = 'National' AND city_name = '$LocalCity')) ORDER BY start_activity ASC";
</font id=code></pre id=code>

Hope that makes sense - it's off a production site so I know it works <img src=../images/dmxzone/forum/icon_smile.gif border=0 align=middle>
Replied 05 Apr 2007 07:45:54
05 Apr 2007 07:45:54 Kiel Fellow replied:
Ohhh thanks so much for that it had me stumped
all I did was use OR instead of AND and it worked
the answers always turn out to be simple

Reply to this topic