Re: dead loop
| From: | Toby Butzon | Date: | Sun, 03 Dec 2000 10:51:12 +0000 |
| Subject: | Re: dead loop | ||
| References: | 1 | Groups: | php.db |
| Request: | Send a blank email to php-db+get-4974@lists.php.net to get a copy of this message | ||
Try limiting the condition of the suspect for-loop and see what you get. For instance, instead of:
for($i=1;$i<=$max;$i++) ...etc...
use this:
for($i = 1; $i <= 100 && $i <= $max; $i++) ...etc...
The error could be somewhere else... if it's in this loop, the script will stop in time with
this added condition so it won't use up all your memory and we'll know to concentrate on
this. Let me know what happens :)
Toby Butzon
[ criticism spurs improvement ]
----- Original Message -----
From: catteddy
To: php-db@lists.php.net
Sent: Saturday, December 02, 2000 5:42 PM
Subject: [PHP-DB] dead loop
Hello, I'm Teddy. I write a program file like belo using PHP
<?php
require 'functions.php';
$link = mssql_connect($DB_SERVER,$DB_LOGIN,$DB_PASSWORD);
if(!$link) {
DisplayErr("Can not connect to the DB");
exit();
}
$SEC_DB = mssql_select_db($DB,$link);
if(!$SEC_DB) {
DisplayErr("Can not select the DB");
exit();
}
$result = mssql_query("SELECT Q_ID FROM Quiz_Content WHERE Subject_ID = 2",$link);
if(!$result) {
DisplayErr("Can not execute the statement");
exit();
}
$max = mssql_num_rows($result);
echo $max;
$ran_s[] = 0;
while($row = mssql_fetch_array($result)) {
$ran_s[] = $row["Q_ID"];
}
reset($ran_S);
for($i=1;$i<=$max;$i++) {
echo $ran_s[$i];
echo "<BR>";
}
?>
I was using WindowNT4.0 as the web server and Microsoft SQL2000. They both install in the same
machine(PII 400 with 128MB RAM).
Every time I execute the program. It just use up almost all the resource in the NT. When I see the
TaskManager. PHP is using 99% resource.
I had ever try another methord to output the result. The problem may occur in the last For loop.
It just display some number very big. I had attach the script of the table.
Please help me!
Thanks a lot
Teddy
------------------------------------------------------------------------------
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, e-mail: php-db-unsubscribe@lists.php.net
For additional commands, e-mail: php-db-help@lists.php.net
To contact the list administrators, e-mail: php-list-admin@lists.php.net