php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #15143 Large loop doesn't work.
Submitted: 2002-01-21 09:37 UTC Modified: 2002-01-28 09:29 UTC
From: bkirk at uss dot com Assigned:
Status: Closed Package: Apache related
PHP Version: 4.1.1 OS: Win 2K
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: bkirk at uss dot com
New email:
PHP Version: OS:

 

 [2002-01-21 09:37 UTC] bkirk at uss dot com
This code doesn't seem to work with more than 20 people.  I had it working great with 12 and then I added all 61 and the page just sits there and doesn't load.  On IE or Netscape so it is the Apache or PHP.  I am using the php.exe in apache not the module.  I couldn't get the module to work correctly.  I am using the latest stable versions of apache, mysql, and php.  I also am using the mysql-nt-max.  I don't think it is a problem with mysql cause I had a simular problem with a calendar program, yet when I didn't have tables (loop in a loop, just listed it straight out) it worked fine.

When I eliminate the tables in this program I get up to about line 20 before it just hangs forever.  I waited about 3 hours to see if it loaded and it never stops trying.


<html>
  <head>
    <title>Football Playoff Picks Standings</title>
  </head>
  <body bgcolor=#ffffff>
    <?php
	$select="select a.nickname, round(sum(pow(2,a.round+1))),sum(1) from user_picks a, actual_wins b where a.round=b.round and a.division=b.division and a.winner=b.winner group by nickname order by 2 desc, 1 desc";
	$select_tot="select sum(1) from actual_wins";
	mysql_connect("localhost","root","Ushouldn'tBhere");
	$result = mysql_db_query("football",$select);
	$result_tot = mysql_db_query("football",$select_tot);
	$row_tot = mysql_fetch_array($result_tot);
	echo "<center><table border=1>";
	echo "<tr><td></td><th><font size=+2>Place</font></th><th><font size=+2>Nickname</font></th><th><font size=+2>Points</font></th><th><font size=+2>Percentage</font></th></tr>";
	$cnt = 1;
	while($row = mysql_fetch_array($result)) {
	  $select="select winner from user_picks where round=3 and nickname='".$row["nickname"]."'";
	  $result2 = mysql_db_query("football",$select);
	  $row2 = mysql_fetch_array($result2);
        $nickname = urlencode($row["nickname"]);
	  echo "<tr><td><center><img src=\"images/icons/".$row2["winner"].".gif\"></center></td>";
	  echo "<td><font size=+1><center>".$cnt."</center></font></td>";
	  echo "<td><font size=+1><center><a href=\"picks.php?nickname=".$nickname."\">".$row["nickname"]."</a></center></font></td>";
	  echo "<td align=right><font size=+1>".$row[1]."</font></td>";
	  $percentage=round($row[2]/$row_tot[0]*100);
	  echo "<td align=right><font size=+1>".$percentage." %</font></td></tr>";
	  mysql_free_result($result2);
	  $cnt++;
 	}
	echo "</table></center>";
	mysql_free_result($result);
    ?>
  </body>
</html>

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2002-01-21 09:46 UTC] sander@php.net
Can you simplify the code and track down the problem to only a few lines of code?
 [2002-01-21 11:54 UTC] bkirk at uss dot com
The selects in a loop is what does it.  If I remove the select statement it seems to work fine in this program.  Is there some kind of limit to how many selects on php page can handle?  or am I not releasing the sql functions correctly?  I also notice that everytime I have a page loading I see a new process for php.exe in the process tab under task manager.  

	while($row = mysql_fetch_array($result)) {
	  $select="select winner from user_picks where round=3 and nickname='".$row["nickname"]."'";
	  $result2 = mysql_db_query("football",$select);
	  $row2 = mysql_fetch_array($result2);
        $nickname = urlencode($row["nickname"]);
	  echo "<tr><td><center><img src=\"images/icons/".$row2["winner"].".gif\"></center></td>";
	  echo "<td><font size=+1><center>".$cnt."</center></font></td>";
	  echo "<td><font size=+1><center><a href=\"picks.php?nickname=".$nickname."\">".$row["nickname"]."</a></center></font></td>";
	  echo "<td align=right><font size=+1>".$row[1]."</font></td>";
	  $percentage=round($row[2]/$row_tot[0]*100);
	  echo "<td align=right><font size=+1>".$percentage."%</font></td></tr>";
	  mysql_free_result($result2);
	  $cnt++;
 	}

 [2002-01-22 15:32 UTC] bkirk at uss dot com
This same problem doesn't occur on Redhat with Apache, php, and mysql.  Are there limitations to php.exe on win2k?
 [2002-01-26 00:32 UTC] webmaster at lxtype dot com
bkirk@uss.com, try executing the script via the command prompt in Win2k, ex:


start->run: "cmd"

cd web\php

php.exe -f myscript.php

If that hangs, something is amiss indeed. If it just keeps spitting out HTML, the loop is going on forever, which is bad. :-)

Also a totally off the topic thought, if you are going to be using subqueries, look into other databases that allow recursive queries.
 [2002-01-28 09:29 UTC] bkirk at uss dot com
PHP Warning:  mysql_db_query is deprecated; use mysql_select_db() and mysql_query() instead in C:\Program Files\Apache Group\PHP\standingAll.php on line 19

This is a warning that I was getting.  Thanks for the command line info it allowed me to see this and I was able to fix it with this warning info.  Now the page loads fine.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Dec 27 16:01:29 2024 UTC