Solved

Code gone bad

Posted on 2007-03-22
5
188 Views
Last Modified: 2008-03-06
Is there something wrong with this code because when I use it the page just keeps loading and loading and loading...  I have to close out the browser to do anything.

<?php
} elseif ($_GET['review'] == "review") {

$SQLstr = mysql_query("SELECT DISTINCT strCompanyname FROM tblReviews ORDER BY strCompanyName")
or die("SQL statement is not working");

$i = 0;
while ($i < 3) {
      $i = $i+1;
      if ($i == 1) {
            echo("<tr>");
      }
      echo("<td>");
?>
     <a href="/admin/edit_reviews.php?Company=<?= $strCompanyname ?>" >
       <?= $strCompanyname ?>
     </a>
<?php
      echo("</td>");
      if ($i == 3) {
             echo("</tr>");
            $i = 0;
      }
      }
}
?>
0
Comment
Question by:pingeyeg
5 Comments
 
LVL 143

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 300 total points
ID: 18771446
you are looping endless around i = 0..1..2..3 .. 0..1...2..3 ... etc, as you do not "read" the query !!!

<?php
} elseif ($_GET['review'] == "review") {

$SQLstr = mysql_query("SELECT DISTINCT strCompanyname FROM tblReviews ORDER BY strCompanyName ")
or die("SQL statement is not working");

$i = 0;
while ($row = mysql_fetch_assoc($SQLstr))
{
      $i++;
      $strCompanyname = $row["strCompanyname"];

      if ($i == 1) {
            echo("<tr>");
      }
      echo("<td>");
?>
     <a href="/admin/edit_reviews.php?Company=<?= $strCompanyname ?>" >
       <?= $strCompanyname ?>
     </a>
<?php
      echo("</td>");
      if ($i == 3) {
             echo("</tr>");
            $i = 0;
      }
      }
}
?>
0
 
LVL 20

Assisted Solution

by:steelseth12
steelseth12 earned 50 total points
ID: 18771448
$i is never less than 3 thus your are stuck in an infinite loop
0
 
LVL 1

Author Comment

by:pingeyeg
ID: 18771472
angelIII, you sound angry??
0
 
LVL 11

Assisted Solution

by:elfe69
elfe69 earned 150 total points
ID: 18771485
$i can never be > 3 because when it reaches 3 you set it to 0 again in:

 if ($i == 3) {
             echo("</tr>");
            $i = 0;
      }

And your query result is never used...
0
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 18771537
>angelIII, you sound angry??
nope. just put exclamation marks to show that that "detail" was important (should have jumped into your eyes :-) )
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article will explain how to display the first page of your Microsoft Word documents (e.g. .doc, .docx, etc...) as images in a web page programatically. I have scoured the web on a way to do this unsuccessfully. The goal is to produce something …
Generating table dynamically is the most common issue faced by php developers.... So it seems there is a need of an article that explains the basic concept of generating tables dynamically. It just requires a basic knowledge of html and little maths…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question