PDA

View Full Version : Where is my infinite loop? (and other questions)


Crazydog
12-06-2006, 12:12 AM
I'm starting to write this code, and I think I created an infinite loop somewhere, as when this code is run the page loads and never actually displays any info

<?php
$n=0;
$id=$_POST[$n.'add'];
include ('sql.php');
mysql_connect(localhost,$user,$password);
@mysql_select_db($database) or die("Unable to select database");
$query="SELECT * FROM codes WHERE id='$id'";
$result=mysql_query($query);

if ($id != ''){
$id2=$_POST[$n.'add'];
while ($id2 != '' or $id2 == '') {

$email=mysql_result($result, 0, "email");
echo $email.'<br>';
$n++;
}
}else{
mysql_close();
}
?>

Here are my problems.
I have checkboxes, and

If I select the first checkbox, I get an infinite loop of $email being displayed.

If I select the first and second checkboxes, I get an infinite loop of $email (of the First checkbox) displayed.

If I don't select the first checkbox (With any other combination) nothing displays.

ralph l mayo
12-06-2006, 12:24 AM
Unless $id2 is Shrodinger's variable, it's never going to be both empty and not empty.

Spookster
12-06-2006, 12:26 AM
Unless $id2 is Shrodinger's variable, it's never going to be both empty and not empty.

LOL :)

Crazydog
12-06-2006, 12:29 AM
that's why I had it set to or, because it seemed to be stopping at unchecked checkboxes even when there were more checked after it, so i threw that in with that if statement, which now looking at it again looks like its in the wrong place

Spookster
12-06-2006, 01:04 AM
Your infinite loop is caused because you are checking for either condition if it is empty or not empty. Of course it will always be one or the other so the loop will continue to loop.