I have looked thru many solutions that are similar but can not find one that meets my requirements.
I want to limit my users to creating more than two shortURL per url in a 24 hour period
people are abusing this and creating 10+ urls and its clogging up my database. so i want to limit them to 2 per url and leave a message if they have exceeded that
right now i have this check to see if how many they have done per url
$sql = "SELECT * FROM ShortUrls WHERE user_id='$user' AND vidID='$urlMe' AND time > UNIX_TIMESTAMP(DATE_SUB(NOW(), INTERVAL 1 DAY))";
$result = $conn->query($sql);
echo "user created this many urls: " .$result->num_rows;
if ($result->num_rows > 2) {
// keep checking till find one less that 2
}
Loop thru the database of urls and check if they used that same url more than twice in 24 hours. if they have not used that url more than twice in 24 hours they can create a new Shortened URL with that url.
EDIT the solution i used:
$sql2 = "SELECT tube.vidID FROM tube LEFT JOIN ( SELECT COUNT(*) c, vidID FROM ShortUrls WHERE user_id='$user' AND time > UNIX_TIMESTAMP(DATE_SUB(NOW(), INTERVAL 1 DAY)) GROUP BY vidID ) urls ON urls.vidID = tube.vidID WHERE urls.c < 2 LIMIT 1;";
$result = $conn->query($sql2);
if ($row = $result->fetch_assoc()) {
echo "You can add a URL to this video: " . htmlspecialchars($row['vidID']);
} else {
echo "All videos used up!";
}
Hope this can be useful to others