How to JQuery PHP AJAX filter based on multiple checkbox product - ajax

I am working on a job site on which jobs will have categories titles like, salary, Sector, Location etc. The idea is to enable a visitor to filter out posts by selecting appropriate checkboxes for all these three categories and show the posts which contains category parameters chosen by the user. Here is an example of what i am looking for : http://underwearking.nl/heren/ (see the left sidebar)
I have gone through over 200 plugins and searched wordpress thoroughly but i am unable to find any plugin which fulfills this. Also, I don't know much about coding but i know that it involves something like integration of jQuery Ajax and checkboxes... Can someone please help me???

Try UNION ALL:::
select distinct wp_usermeta.user_id, wp_users.user_nicename
FROM wp_usermeta
LEFT JOIN wp_users
ON wp_usermeta.user_id=wp_users.ID
ORDER BY wp_usermeta.user_id
UNION ALL
select distinct t1.user_id ,t2.meta_value shop from wp_usermeta as t1, wp_usermeta as t2 where t1.user_id = t2.user_id and ( (t1.meta_key = 'category' and t1.meta_value like '%$catid%') ) and t2.meta_key='shop_name' order by t2.meta_value ASC

You can an extra JOIN to that table p_usermeta in the same query, then LEFT JOIN the wp_users the same way you did, something like this:
SELECT distinct
t1.user_id,
wp_users.user_nicename,
t2.meta_value shop
FROM wp_usermeta AS t1
INNER JOIN wp_usermeta as t2 ON t1.user_id = t2.user_id
LEFT JOIN wp_users ON t1.user_id = wp_users.ID
where ((t1.meta_key = 'category' and t1.meta_value like '%$catid%'))
and t2.meta_key='shop_name'
ORDER BY wp_usermeta.user_id, t2.meta_value
LIMIT 1,10"

Related

Performance: LEFT JOIN vs SUBQUERY

I'm using PostgreSQL 9.3 and have the following tables (simplified to only show the relevant fields):
SITES:
id
name
...
DEVICES:
id
site_id
mac_address UNIQUE
...
Given the mac_address of a particular device, and I want to get the details of the associated site. I have the following two queries:
Using LEFT JOIN:
SELECT s.* FROM sites s
LEFT JOIN devices d ON s.id = d.site_id
WHERE d.mac_address = '00:00:00:00:00:00';
Using SUBQUERY:
SELECT s.* FROM sites s
WHERE s.id IN (SELECT d.site_id FROM devices d WHERE d.mac_address = '00:00:00:00:00:00');
Which of the two queries would have the best performance over an infinitely growing database? I have always leaned towards the LEFT JOIN option, but would be interested to know how the performance of both rates on a large data set.
It generally won't make any difference, because they should result in the same query plan. At least, an EXISTS subquery will; IN isn't as always as intelligently optimised.
For the subquery, rather than using IN (...) you should generally prefer EXISTS (...).
SELECT s.*
FROM sites s
WHERE EXISTS (
SELECT 1
FROM devices d
WHERE d.mac_address = '00:00:00:00:00:00'
AND d.site_id = s.id
);

Using an alias in a select statement in a join query

I am very new at using Oracle (in the class now). I have a problem with the query I am trying to run. I have researched a lot of other answers on this site and none of them seem to apply directly to my problem so the solutions aren't working.
I need to find the total amount spent on lunches by each employee.
Show first_name, last_name, credit_limit, and total_price_spent in your results.
Order the answer by total_price_spent in descending order. Only show the employees who spent more than their credit limit.
I figured out how to do everything but the part about showing only the employees who spent more than their credit limit. I tried to use a select statement at the end but discovered that I can't use an alias in a select statement so I don't really know where to go from here. Any help would be appreciated. This is what I have so far.
select a.first_name, a.last_name, credit_limit, sum(c.quantity * d.price) as total_price_spent
from l_employees a join l_lunches b on a.employee_id = b.employee_id join l_lunch_items c on b.lunch_id = c.lunch_id join l_foods d on c.supplier_id = d.supplier_id and c.product_code = d.product_code
group by a.first_name, a.last_name, a.credit_limit
order by total_price_spent desc;
As Mike said : Add HAVING
select a.first_name, a.last_name, credit_limit, sum(c.quantity * d.price) as total_price_spent
from l_employees a join l_lunches b on a.employee_id = b.employee_id join l_lunch_items c on b.lunch_id = c.lunch_id join l_foods d on c.supplier_id = d.supplier_id and c.product_code = d.product_code
group by a.first_name, a.last_name, a.credit_limit
having sum(c.quantity * d.price) > credit_limit
order by total_price_spent desc;
I think what you're looking for is a HAVING clause. It's like a WHERE, but is used when you're using group by. You want to drop it in between the group by and order by. Something like 'HAVING total > a.credit_limit' should work. If using the alias 'total' doesn't work (haven't tested this), you might have to do 'sum(c.quantity * d.price)' again in the HAVING clause instead of using total, so HAVING sum(c.quantity * d.price) > a.credit_limit.

Union query with left join : Group & Ordering Issues

I have finally figured out how to perform a somewhat successful UNION query with left joins! Yeah (snaps for me)..
Now, the problem I'm running into is that I can get it to Group them so that I only have one entry for each code...
SELECT vg.*, lh.*
FROM tbl_vluchtgegevens vg
INNER JOIN tbl_luchthaven lh
ON lh.luchthavenID = vg.vertrekluchthaven
UNION
SELECT vg.*, lh.*
FROM tbl_vluchtgegevens vg
INNER JOIN tbl_luchthaven lh
ON lh.luchthavenID = vg.aankomstluchthaven
GROUP BY lh.luchthavencode;
I've tried grouping based on the luchthavencode, which is what i'm displaying. I've tired the luchthavenID...
Here is a sample of what I am trying to accomplish (note: I did not spend a lot of time reproducing the field names in my tables, I just used some shorthand, i will translate that later)
Here is an example of what I am trying to achieve. This board won't let me post until I have at least 10 reputation.
http://globe-trekking.com/union_query_example.jpg
kind of pulling my hairs out on this... though i'm sure it's simple?
Any help would be great!
Regards,
Try this and see if it fits for you
SELECT
Luchthaven.Luchthaven.luchthavencode as CODE,
Luchthaven.luchthavennaam as NAME
FROM
Luchthaven , Vluchtgegens
WHERE
Luchthaven.LID = Vluchtgegens.vertrek AND
Luchthaven.LID = Vluchtgegens.aankomst AND
ORDER BY Luchthaven.luchthavennaam DESC
GROUP BY Luchthaven.luchthavennaam
I was able to get it by using:
select *
from
(
SELECT vg.vertrekluchthaven AS code
FROM tbl_vluchtgegevens vg
WHERE vg.vertrekdatum <=NOW()
UNION
SELECT vg.aankomstluchthaven AS code
FROM tbl_vluchtgegevens vg
WHERE vg.vertrekdatum <=NOW()
) vg
INNER JOIN tbl_luchthaven lh
ON lh.luchthavenID = vg.code
Group by vg.code
Order by lh.luchthavencode;
Thanks for your help... sorry if my thought process was not very clear.

How can i perform this query in NHibernate for getting child count

select name,
(select count(*) from products where products.category_Id=categories.Id) as productCount
from categories
session.CreateCriteria<Category>()
but whats next?
i don't even know how to search it in Google?
think of your query like
SELECT categories.Id, count(categories.Id)
FROM categories inner join products on products.category_Id=categories.Id
group by categories.Id
I think they will produce the same result.
search google for
nhibernate criteria join
and
CreateAlias

Linq To Entity Framework selecting whole tables

I have the following Linq statement:
(from order in Orders.AsEnumerable()
join component in Components.AsEnumerable()
on order.ORDER_ID equals component.ORDER_ID
join detail in Detailss.AsEnumerable()
on component.RESULT_ID equals detail.RESULT_ID
where orderRestrict.ORDER_MNEMONIC == "MyOrderText"
select new
{
Mnemonic = detail.TEST_MNEMONIC,
OrderID = component.ORDER_ID,
SeqNumber = component.SEQ_NUM
}).ToList()
I expect this to put out the following query:
select *
from Orders ord (NoLock)
join Component comp (NoLock)
on ord .ORDER_ID = comp.ORDER_ID
join Details detail (NoLock)
on comp.RESULT_TEST_NUM = detail .RESULT_TEST_NUM
where res.ORDER_MNEMONIC = 'MyOrderText'
but instead I get 3 seperate queries that select all rows from the tables. I am guessing that Linq is then filtering the values because I do get the correct values in the end.
The problem is that it takes WAY WAY too long because it is pulling down all the rows from all three tables.
Any ideas how I can fix that?
Remove the .AsEnumerable()s from the query as these are preventing the entire query being evaluated on the server.

Resources