?
Solved

Code gone bad

Posted on 2007-03-22
5
Medium Priority
?
206 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 143

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 1200 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 200 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 600 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

Don't Cry: How Liquid Web is Ensuring Security

WannaCry is just the start. Read how Liquid Web is protecting itself and its customers against new threats.

Question has a verified solution.

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

Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
Many old projects have bad code, but the budget doesn't exist to rewrite the codebase. You can update this code to be safer by introducing contemporary input validation, sanitation, and safer database queries.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to count occurrences of each item in an array.
Suggested Courses

762 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