Solved

Code gone bad

Posted on 2007-03-22
5
163 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 142

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 142

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this.Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it is …
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
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.

744 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now