Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Order by date and by slug, to handle the edge case where the last two…

… entries have the same date

Ref. #6.
  • Loading branch information...
commit 0167b9e9fd4f95c3645bf25df8c49cc8a0ac2bad 1 parent f8d4578
@B-Scan B-Scan authored committed
Showing with 1 addition and 1 deletion.
  1. +1 −1  shorten.php
View
2  shorten.php
@@ -36,7 +36,7 @@ function getNextShortURL($s) {
if ($result && $result->num_rows > 0) { // If there’s already a short URL for this URL
die(SHORT_URL . $result->fetch_object()->slug);
} else {
- $result = $db->query('SELECT slug, url FROM redirect ORDER BY date DESC LIMIT 1');
+ $result = $db->query('SELECT slug, url FROM redirect ORDER BY date DESC, slug DESC LIMIT 1');
if ($result && $result->num_rows > 0) {
$slug = getNextShortURL($result->fetch_object()->slug);
if ($db->query('INSERT INTO redirect (slug, url, date, hits) VALUES ("' . $slug . '", "' . $url . '", NOW(), 0)')) {
Please sign in to comment.
Something went wrong with that request. Please try again.