while not parsing

Hey guys. So, I’m really not sure why, but this snippet of code is just not working. I’ve had similar issues before but I’ve been able to work around them. Anyways, the issue is marked by comment marks. The while portion that I’m trying to get to work is the $zerocounter. It is set immediately above the while code, and yet, the while code fails every time. I feel it’s something simple I’m missing, but… hopefully you guys can help me out. Any questions, feel free to ask. Thanks!

[php]
$slotzero = “SELECT * FROM t_monsters WHERE trainer = ‘$obtainusers3[Username]’ AND slot = ‘0’”;
$slotzero2 = mysql_query($slotzero) or die(“Slot zero check fail - count – Ln 24.”);
$slotzero3 = mysql_num_rows($slotzero2);
print “

$slotzero3 monsters had a slot of zero.”; //record keeping

if(!($slotzero3 = 0)){ //says if any monsters have a slot number of zero
$getzeros1 = “Select * from t_monsters where trainer = ‘$obtainusers3[Username]’ and slot = ‘0’ order by ID ASC”;
$getzeros2 = mysql_query($getzeros1) or die(“Get zeros fail - Ln 29.”);
print “Zeros changed:”;
$getzeros = mysql_fetch_array($getzeros2);
while($getzeros = mysql_fetch_array($getzeros2)){ //goes thru the list of monsters slot 0, much like roster displays the list
$zerocounter = 0;
print “Pass on line 33”; //just test to see if the while above passed
//Issue is with immediate below while code. with == it loops continuously, with = it bypasses
while($zerocounter == 0){
print $getzeros[Slot];
$newslot = $getzeros[Slot] + 1;
print $newslot;
$updatezeros = “Update t_monsters set slot = ‘$newslot’ where trainer = ‘$obtainusers3[Username]’ and id=’$getzeros[ID]’”;
mysql_query($updatezeros) or die(“Update zeros slots fail. - Ln 36”);
$newzerocheck = “Select * from t_monsters where trainer = ‘$obtainusers3[Username]’ and slot = ‘$newslot’”;
$newzerocheck2 = mysql_query($newzerocheck) or die(“New zero check die. - Ln 38”);
$newzerocheck3 = mysql_num_rows($newzerocheck2);

print “Monster:$getzeros[Monster] ID:$getzeros[ID]
”;
if($newzerocheck3 > 1){//checks to see if new slot for monster is already held. if so, keeps value at zero so that
//previous while is performed and a new slot is obtained
$zerocounter = 0;
}
elseif($newzerocheck3 = 1){ // if the monster is only one with this slot for this trainer, sets value to 1 so that can move on to next
// monster in the sequence of those with a slot of 0
$zerocounter = 1;
}
else{
die(“Zerocheck is coming back < 1… something is jacked up.”);
} //end of else from zerocheck
}// end of while from zerocounter
} // end of while for getzeros
print “

”;
} // end of if for slotzeros - at this point should no longer have monsters with a slot of zero for the trainer.
[/php]

any error message?

Hi alexoldshane,

You are resetting the variables in your Ifs instead of comparing them as you intend. For example:[php]if(!($slotzero3 = 0)){ //says if any monsters have a slot number of zero[/php]
…You are setting $slotzero3 = 0 (effectively this executes the same as[php]if(!0)) {[/php]I would do:[php]if($slotzero3 > 0)){[/php]
You could also do:[php]if(!($slotzero3 == 0)){[/php]or[php]if($slotzero3 != 0){[/php]
You will need to fix this logic in at least one other if statement in your code.

It also looks like you are immediately running the same exact query again. Why not just continue to use the results from the initial query. You can simply continue to use $slotzero2 instead of $getzeros2, or you can set $getzeros2 = $slotzero2 if you prefer.

I’ll look over the rest of the code, but wanted to at least get you started…

Sponsor our Newsletter | Privacy Policy | Terms of Service