Actually, yeah. Code isn't fix. I ended up just removing the entire "zero fix" portion and made it so that it would update them all to 1 so that it could be taken care of in the next portion of the code.
However, I'm still having a similar issue.
Reason they are linked is due to I've never actually heard of triggers. Learned mysql on the fly while helping buddy fix his site, and so I've been using what I can get by on.
The database never really had a "good" backup. The real issue is that the roster file is currently out of whack. It is setting values to things that it shouldn't for some reason, and I've yet had time to take a look at it. But I need to fix this before I can fix that - otherwise it'll be a manual fix and I'd rather not have to sift and compare against 3000 lines of mysql having to go back and forth between 2 tables to check values.
I suppose I could do the duplicate calling, but I'm honestly not sure how I'd do it. I can logically think it, but not being able to perform mysql with operators such as > and such kinda kill my process.
Programmatically finding next unused value, would be great. Honestly, I'd prefer it that way. However, I've no idea how other than the method I'm working now. The slots need to be in numerical order without a gap: 1,2,3,4,5... works whereas 1,3,4,5,7 would almost break my system.
This is currently the most updated copy of my "rosterfix" file that I have. Maybe seeing the entire thing would give you more insight?
<?php
$useridcounter = 1;
$usercheck = "Select * from trainers where userID = '$useridcounter'";
$usercheck2 = mysql_query($usercheck) or die("User check fail - ln 5");
$usercheck3 = mysql_num_rows($usercheck2) or die("Initial usercheck die - Ln5.");
print "<table>";
while($usercheck3 > 0){ //maintains that a user exists at X id
$obtainusers = "SELECT * FROM `trainers` where userID = '$useridcounter'";
$obtainusers2 = mysql_query($obtainusers) or die("Could not obtain user -Ln 11.");
$obtainusers3 = mysql_fetch_array($obtainusers2);
print"<table> <tr><td>---$obtainusers3[Username]---</td></tr>"; //record keeping
$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 "<tr><td>$slotzero3 monsters had a slot of zero.</td></td>"; //record keeping
if(!($slotzero3 = 0)){ //says if any monsters have a slot number of zero
mysql_query("Update t_monsters set slot = '1' where slot ='0'");
} // end of if for slotzeros - at this point should no longer have monsters with a slot of zero for the trainer.
//selects all monsters of the trainer
$getmonsterinfo = "Select * from t_monsters where trainer = '$obtainusers3[Username]' order by slot ASC";
$getmonsterinfo2 = mysql_query($getmonsterinfo) or die("Get monster info die - Ln 20.");
while($monsterinfo = mysql_fetch_array($getmonsterinfo2)){ //check every monster trainer has in order of slot
$slotcounter = 0;
while($slotcounter == 0){// checking one monster
$slotchecker1 = "Select * from t_monsters where trainer = '$obtainusers3[Username]' and slot = '$monsterinfo[Slot]'";
$slotchecker2 = mysql_query($slotchecker1) or die("Slotchecker failed getting count - Ln 62.");
$slotcheck = mysql_num_rows($slotchecker2);
if($slotcheck == 0){ //no monsters exist at this location, therefore, can ignore
$slotcounter = 1;
}
elseif($slotcheck == 1){ // if no monster has this slot, its good - allows process to move on
$slotcounter = 1;
print "<tr><td>$monsterinfo[Monster] ID:$monsterinfo[ID] should be good.</td></tr>";
}
elseif($slotcheck > 1){ // if more than one monster has this slot perform:
$newnonzeroslot0 = $monsterinfo[Slot] ; //Initially had '$newnonzeroslot = $monsterinfo[Slot] +1' but wasn't updating properly
$newnonzeroslot = $newnonzeroslot0 + 1; // increases slot by one
print "<tr><td>$monsterinfo[Monster] ID:$monsterinfo[ID] was moved from slot $monsterinfo[Slot]
to slot $newnonzeroslot</td></tr>"; //record keeping
$updatenonzero = "Update t_monsters set Slot = '$newnonzeroslot' where ID ='$monsterinfo[ID]'
AND Trainer = '$monsterinfo[Trainer]'";
mysql_query($updatenonzero) or die("Could not update nonzero-slot increase - Ln 69."); //updates mysql for later comparison
}
}//end of second while
}
//This below is mostly just to ensure that the variables that are linked between the two tables are accurate
$newstarter = "Select * from t_monsters where trainer = '$obtainusers3[Username]' and slot = '1'";
$newstarter2 = mysql_query($newstarter) or die("calling slot one monster of trainer failed - Ln 84.");
$newstarter3 = mysql_fetch_array($newstarter2);
$newsecond = "Select * from t_monsters where trainer = '$obtainusers3[Username]' and slot = '2'";
$newsecond2 = mysql_query($newsecond) or die("calling slot two monster of trainer failed. - Ln 85");
$newsecond3 = mysql_fetch_array($newsecond2);
$newthird = "Select * from t_monsters where trainer = '$obtainusers3[Username]' and slot = '3'";
$newthird2 = mysql_query($newthird) or die("calling slot three monster of trainer failed - Ln 86.");
$newthird3 = mysql_fetch_array($newthird2);
$Updatestarters = "Update trainers set Starter = '$newstarter3[ID]' where Username = '$obtainusers3[Username]'";
mysql_query($Updatestarters) or die("Could not update new starter in trainer DB. Ln-91");
$Updatesecond = "Update trainers set Second = '$newsecond3[ID]' where Username = '$obtainusers3[Username]'";
mysql_query($Updatesecond) or die("Could not update new second in trainer DB - Ln 93");
$Updatethird = "Update trainers set Third = '$newthird3[ID]' where Username = '$obtainusers3[Username]'";
mysql_query($Updatethird) or die("Could not update new third in trainer DB - Ln 95");
print "<tr><td> </td></tr><tr><td>New Starters:</td></tr>
<tr><td>Starter:</td><td>$newstarter3[Monster] ID:$newstarter3[ID]</td></tr>
<tr><td>Second:</td><td>$newsecond3[Monster] ID:$newsecond3[ID]</td></tr>
<tr><td>Third:</td><td>$newthird3[Monster] ID:$newthird3[ID]</td></tr></table>";
$useridcounter = $useridcounter +1;
$obtainusers = "SELECT * FROM `trainers` where userID = '$useridcounter'";
$obtainusers2 = mysql_query($obtainusers) or die("Could not obtain user -Ln 101.");
if($obtainusers2 != ''){
$usercheck3 = mysql_num_rows($obtainusers2) or die("Initial usercheck die - Ln 102.");
}
} // end of while function to check against every trainer - basically end of file.
print "</table>";
?>