Hi, im new here so i hope i get this all understandable for everyone.

But i have been having issues with this script designed to stop overlapping entries in a mysql "users" table, and using Unique keys simply is not applicable in this scenario.

First off here is the script :
CODE

// Check if overlaps are made
// Find Total
$Query1 = "SELECT UserN, COUNT(UserN) FROM users";
$Result1 = mysql_query($Query1) or die(mysql_error());
$Row1 = mysql_fetch_array($Result1);
$Total = $Row1['COUNT(UserN)'];
// Init Variables
$Temp1=$Total;
$Temp2=$Total;
$Temp3=$Total;
$A=1;
$B=1;
$C=1;

// UserN While LOOP
while( $A <= $Total) {
$L1Q = mysql_query("SELECT * FROM users WHERE UserID='$A'");
$A=$A+1;
$L2Q = mysql_fetch_array($L1Q);

if ($L2Q['UserN'] =! $UserName) {
$Temp1=$Temp1-1;
}

}

// UserE Loop
for ( $B = 1; $B < $Total; $B += 1) {
$L3Q = mysql_query("SELECT * FROM Users WHERE UserID='$B'");
$L4Q = mysql_fetch_array($L3Q);
if ($L4Q['UserE'] =! $UserEmail)
$Temp2=$Temp2-1;
}

// UserIP Loop
for ( $C = 1; $C < $Total; $C += 1) {
$L5Q = mysql_query("SELECT * FROM Users WHERE UserID='$C'");
$L6Q = mysql_fetch_array($L5Q);
if ($L6Q['IPA'] =! $IP)
$Temp3=$Temp3-1;
}
echo $Temp1 . "<br/>" . $Temp2 . "<br/>" . $Temp3 . "<br/>" . $Total . "<br/>";
// Overlap Check
if (($Temp1 == 0) && ($Temp2 == 0) && ($Temp3 == 0)) {
......................... }


The way i am trying to get this to work is ;

1> The first block of script counts the number of entries that are in the table, so i can set the number of times i need to loop.
2> The next 3 loop [as you can see using both For & While methods] from 1 [the lowest possible userID] to the $Total value, and if there is not a match to the $UserName variable [for example], then there is no overlap in that respective loop and its $TempN is negativly incremented.
3> If any of the $TempN variables are not equal to 0, then the script treats it as an overlap.

## Known issues ##
~ 1> I know there is a bug instantly if a user is deleted that has a UserID between '1' and the value of $Total, due to how i made the $Total block.... [lack of foresight i know....]

~ 2> For some reason the lines
"$L1Q = mysql_query("SELECT * FROM users WHERE UserID='$A'");"
"$L2Q = mysql_fetch_array($L1Q);"
do not return a value if i for example use the debugging line "echo $L2Q['UserN'];"

If you need the users layout to be able to assist just say and il be glad to post it.

Thanks for reading smile.gif
For the record im testing this out on WAMP localhost, so il be able to try out numerous solutions pretty quickly if they are easy to implement and get back to you with the result.