Log in

View Full Version : I'm stumped...



MrRSMan
12-29-2009, 01:34 AM
I have the following code to work out the difference between two fields on successive rows, and this works fine.


$query6="
SELECT t1.id AS id1, t2.id AS id2,
t1.overallr AS overallr1, t2.overallr AS overallr2,
t2.overallr-t1.overallr AS dist
FROM {$table} AS t1, {$table} AS t2
WHERE t1.id+1 = t2.id
ORDER BY t1.id;
";

On another page I'm using the following code to select every 24th row in the table.


$query7="SELECT * FROM {$table} WHERE id = '1' or id % 24 = 0";

But for some reason I can't combine the two concepts. I want to "execute" the first bit of code on every 24th row, instead of all of them.

Thank you in advance- I hope you can help.

bluewalrus
12-30-2009, 11:38 PM
$query7="SELECT ID FROM {$table} WHERE id = '1' or id % 24 = 0";

$fetchedresults

$query6="SELECT t1.id AS id1, t2.id AS id2, t1.overallr AS overallr1, t2.overallr AS overallr2, t2.overallr-t1.overallr AS dist FROM {$table} AS t1, {$table} AS t2 WHERE t1.id+1 = t2.id and t1 = $fetchedresults or t2 = $fetchedresults ORDER BY t1.id; ";


Maybe something like that?