minni
January 3, 2014, 8:39am
1
Hello,
I have a table called priest and it has only two fields - priestid and priestname.
I want to pick up the rows where priestid=1, 5, 9, 13, 17,…till the end of the table
That means I want to pick up every 5th row (difference=4).
In know the statement :
select * from priest where priestid in (1,5,9)
But I want mysql to pick up on its own till the end of the table…I am stuck with this.
The following has not worked either:
$r=1;
$e=1;
while ($e<51)
{
$result = mysql_query(“SELECT * FROM priest where priestid limit $r,1”);
$r=$r+4;
}
Please help !!!
where mod(priestid,4) = 1
Of course with mysql_query now long dead and about to be removed from PHP you really ought to be using mysqli_query instead.
minni
January 3, 2014, 9:25am
4
Thanks a lot… That worked.
One more query…if I leave the IDs and want to show the priest name of the first row, then priestname form the 5th row, then 9th and so on (irrespective of the IDs), how can it be done??
I have tried this with limit and offset but it did not work…
r937
January 3, 2014, 11:43am
5
SELECT priestname
FROM priest AS t
WHERE MOD( ( SELECT COUNT(*)
FROM priest
WHERE priestid < t.priestid ),4) = 0