Jump to content

mysql_query hangs my system.


sepoto

Recommended Posts

The following runs great:

<?php$radio = $_POST['radio'];require('dbconnect.php');$query="SELECT * FROM planning WHERE import_date='" . $radio . "'";$planrec=mysql_query($query);$plannum=mysql_numrows($planrec);echo $plannum . " records from " . $radio . " recordset...</br></br>";while ($planrow = @mysql_fetch_assoc($planrec)) {$cnt = 0;$x = $planrow["lng"];$y = $planrow["lat"];echo $x . ", " . $y . "</br>";		while($cnt < 64) {		$query="SELECT * FROM polygon_2000offsets WHERE id='" . $cnt . "'";		echo $query . "</br>";		$cnt = $cnt + 1;	}	}?>

The queries look great also and run great when I execute them manually inside MySQL Workbench & PHPMyAdmin:

SELECT * FROM polygon_2000offsets WHERE id='0'SELECT * FROM polygon_2000offsets WHERE id='1'SELECT * FROM polygon_2000offsets WHERE id='2'SELECT * FROM polygon_2000offsets WHERE id='3'SELECT * FROM polygon_2000offsets WHERE id='4'SELECT * FROM polygon_2000offsets WHERE id='5'SELECT * FROM polygon_2000offsets WHERE id='6'SELECT * FROM polygon_2000offsets WHERE id='7'SELECT * FROM polygon_2000offsets WHERE id='8'SELECT * FROM polygon_2000offsets WHERE id='9'SELECT * FROM polygon_2000offsets WHERE id='10'SELECT * FROM polygon_2000offsets WHERE id='11'SELECT * FROM polygon_2000offsets WHERE id='12'SELECT * FROM polygon_2000offsets WHERE id='13'SELECT * FROM polygon_2000offsets WHERE id='14'SELECT * FROM polygon_2000offsets WHERE id='15'SELECT * FROM polygon_2000offsets WHERE id='16'SELECT * FROM polygon_2000offsets WHERE id='17'SELECT * FROM polygon_2000offsets WHERE id='18'SELECT * FROM polygon_2000offsets WHERE id='19'SELECT * FROM polygon_2000offsets WHERE id='20'SELECT * FROM polygon_2000offsets WHERE id='21'SELECT * FROM polygon_2000offsets WHERE id='22'SELECT * FROM polygon_2000offsets WHERE id='23'

As soon as "$offs=mysql_query($query);" enters into the picture my system hangs like it is in an infinite loop. I do not know what the problem is nor how to fix it.

<?php$radio = $_POST['radio'];require('dbconnect.php');$query="SELECT * FROM planning WHERE import_date='" . $radio . "'";$planrec=mysql_query($query);$plannum=mysql_numrows($planrec);echo $plannum . " records from " . $radio . " recordset...</br></br>";while ($planrow = @mysql_fetch_assoc($planrec)) {$cnt = 0;$x = $planrow["lng"];$y = $planrow["lat"];echo $x . ", " . $y . "</br>";		while($cnt < 64) {		$query="SELECT * FROM polygon_2000offsets WHERE id='" . $cnt . "'";		$offs=mysql_query($query);		$cnt = $cnt + 1;	}	}?>

Thanks so much for any help out is solving this vexing problem. Thank you.

Link to comment
Share on other sites

It's never a good idea to run queries in a loop. It would be much more efficient to get all results at once and loop through them instead of getting one result per loop. If you have 10 results returned by the outer query, you're going to end up running 640 queries in the loop (and it looks like they're the same 64 every time).

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...