SO Basically i have this problem with this test build of a little project im rewriting and so far its not looking to good
I have multiple tables that are all the same, they have been set up this way for simplicity as far as i can tell.
Tables
+----+----------+-----------------+---------------+-------------------+
| id | sec_id | customer_name | customer_date | etc... |
+----+----------+-----------------+---------------+-------------------+
| 0 | 14328778 | Somebody Once | 2/1/2016 | Role Me I |
+----+----------+-----------------+---------------+-------------------+
| 1 | 14428755 | Told Me The | 2/6/2015 | Aint The Sharpest |
+----+----------+-----------------+---------------+-------------------+
| 2 | 15548447 | World Was Gonna | 2/12/2014 | Tool in the shed |
+----+----------+-----------------+---------------+-------------------+
As you can see from my table above i have the regular id and then this second id
the problem is in the second id number because thats where my duplicates are.
I have about 25 tables like the one above and they are all the same but for different departments and have all different data but are all basically used in the same way
I am in the process of attempting reporting/inserting data into these tables without creating any duplicates and so far i have failed miserably at this
because i have some reported 55 duplicates over the past week out of nearly 1000 entries and while this might not seem like a big deal its continueing to be a huge headache for me because i cant get the data from the tables if one of the sec_id's are similar to another tables sec_id, here is the code i have been using to prevent duplicates so far and i thought it was working but apparently it isnt
do {
$random_number = rand(10000,10000000);
$sql = "(SELECT sec_id FROM depart_table0 WHERE sec_id='".$random_number."')";
for ($i=0; $i < $table_count[0]-7; $i++){
$sql .= "UNION (SELECT sec_id FROM depart_table".$i." WHERE sec_id='".$random_number."')";
}
$sql_response = mysqli_query($con, $sql)or die(mysqli_error($con));
} while (mysqli_num_rows($sql_response) == 1);
Please tell me what im doing wrong because i tested this code before (or at least i thought i thouroghly tested it) and it seemed to work before
Any help or guidance you give is helping a fresh out of college developer learn his way, please and thank you!