I have three tables :
- user_details
- user_badges
- badges
I have a query where I use "insert ignore into" command to insert the badge id from badges and user id from user_details into user_badge.
$username=$_SESSION['username'];
$getlife="SELECT * FROM user_details WHERE username='$username'";
$getlifedb=mysqli_query($db, $getlife);
while ($row=mysqli_fetch_array($getlifedb)){
if($row['fullife'] == '1'){
$full="INSERT IGNORE INTO user_badge(user_id, badge_id)
SELECT u.user_id, b.badge_id
FROM user_details as u
CROSS JOIN badges as b
WHERE u.user_id='$id'
AND b.badge_id='8'";
mysqli_query($db, $full) or die(mysqli_error($db));
}
}
Below is the picture of user_badge table:
But every time I execute the command, the insert ignore doesnt work, but instead it just insert a field again. Can someone help me fix this issue.