Skip to content

Commit

Permalink
Order by date and by slug, to handle the edge case where the last two…
Browse files Browse the repository at this point in the history
… entries have the same date

Ref. mathiasbynens#6.
  • Loading branch information
tombiscan authored and mathiasbynens committed Jul 11, 2012
1 parent f8d4578 commit 0167b9e
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion shorten.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)')) {
Expand Down

0 comments on commit 0167b9e

Please sign in to comment.