but how can I filter the result further, I want two set of results, even and odd results which can be done in mysql query WHERE MOD(pg_id,2) = 1 and WHERE MOD(pg_id,2) = 0
class OddFilterIterator extends FilterIterator{
public function accept(){
return 0 === (parent::key() % 2);
}
}
class EvenFilterIterator extends FilterIterator{
public function accept(){
return 0 !== (parent::key() % 2);
}
}
yes all results but displaying even and odd output… not sure if i am explaining it correctly! but this is suppose to be my original full sql query in my code,
SELECT
pg_id AS ID,
pg_url AS URL,
pg_title AS Title,
pg_content_1 AS Content,
EXTRACT(DAY FROM pg_created) AS Date,
EXTRACT(MONTH FROM pg_created) AS Month,
EXTRACT(YEAR FROM pg_created) AS Year,
COUNT(*) FROM root_pages WHERE `name` <= 'Beta') AS position
FROM root_pages
WHERE MOD(pg_id,2) = 1
AND root_pages.parent_id = '".$page -> pg_id."'
AND root_pages.pg_id != '".$page -> pg_id."'
AND root_pages.pg_cat_id = '2'
AND root_pages.pg_hide != '1'
ORDER BY pg_created DESC
you see that I want a odd result from this query. then i have another query,
SELECT
pg_id AS ID,
pg_url AS URL,
pg_title AS Title,
pg_content_1 AS Content,
EXTRACT(DAY FROM pg_created) AS Date,
EXTRACT(MONTH FROM pg_created) AS Month,
EXTRACT(YEAR FROM pg_created) AS Year,
COUNT(*) FROM root_pages WHERE `name` <= 'Beta') AS position
FROM root_pages
WHERE MOD(pg_id,2) = 0
AND root_pages.parent_id = '".$page -> pg_id."'
AND root_pages.pg_id != '".$page -> pg_id."'
AND root_pages.pg_cat_id = '2'
AND root_pages.pg_hide != '1'
ORDER BY pg_created DESC
SELECT
u.pg_id AS ID,
u.pg_url AS URL,
u.pg_title AS Title,
u.pg_content_1 AS Content,
@rownum:=@rownum+1 AS rownum
FROM (
SELECT pg_id, pg_url,pg_title,pg_content_1
FROM root_pages
WHERE root_pages.parent_id = '7'
AND root_pages.pg_id != '7'
AND root_pages.pg_cat_id = '2'
AND root_pages.pg_hide != '1'
ORDER BY pg_created DESC
) u,
(SELECT @rownum:=0) r
result,
ID URL Title Content rownum
53 a x x 1
52 b x x 2
43 c x x 3
41 d x x 4
but how can I work on it a bit further - I want to display the odd or even records only like the ones below - is it possible?
odd records,
ID URL Title Content rownum
53 a x x 1
43 c x x 3
even records,
ID URL Title Content rownum
52 b x x 2
41 d x x 4
thank you.
p.s. I don’t quite understand the sql query actually even though I almost got the result, for instance, what do the ‘u’ and ‘t’ mean?