Yikes...you should really change that long ugly query to use WHERE ID IN(x,y,z) ...build it with php code rather than writing out a huge long list.
I'm not even sure what the code is doing but anyway...
I'm not even sure what the code is doing but anyway...