beckjoh Posted March 16, 2008 Share Posted March 16, 2008 I first query a table called Points for all rows. This table holds x and y points in longitude and latitude. I then while loop the results to get each row. I then want to run a new query on a second table called segments in which I will use the stored x,y data as a condition or variable in the query. I can get this to run for one point but not for all the points. Can you use data from one table to use for a query in another table? I would try to use JOIN but the tables do not relate, I just need to evaluate each point, the problem is there are hundreds of points. Here is my code. $pointresults = mysql_query("SELECT * FROM points"); $num_points = mysql_num_rows($pointresults); if($num_points == 0) { echo "No Points in Table, There is an Error!"; } else { // get each row while($mypointrow = mysql_fetch_array($pointresults)) { $thelon = $mypointrow['Longitude']; $thelat = $mypointrow['Latitude']; $result = "SELECT poly_id, Segment_id FROM segments WHERE ( longa > $thelng OR longb > $thelng ) AND ( (lata > $thelat AND latb < $thelat ) OR (latb > $thelat AND lata < $thelat ) )"; $result2=mysql_query($result); $resultnumrows = mysql_num_rows($result2); Any help would be appreciated. Quote Link to comment Share on other sites More sharing options...
Barand Posted March 16, 2008 Share Posted March 16, 2008 Consistency in variable names helps $thelon = $mypointrow['Longitude']; $thelat = $mypointrow['Latitude']; $result = "SELECT poly_id, Segment_id FROM segments WHERE ( longa > $thelng OR longb > $thelng ) AND ( (lata > $thelat AND latb < $thelat ) OR (latb > $thelat AND lata < $thelat ) )"; Quote Link to comment Share on other sites More sharing options...
beckjoh Posted March 16, 2008 Author Share Posted March 16, 2008 Sorry, You are right but I fixed the variable names and it still only loops one set of points. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.