Skip to content

Instantly share code, notes, and snippets.

@kmelve
Last active April 15, 2016 04:21
Show Gist options
  • Select an option

  • Save kmelve/8ee82ad4371d66756e759d66a8b6a020 to your computer and use it in GitHub Desktop.

Select an option

Save kmelve/8ee82ad4371d66756e759d66a8b6a020 to your computer and use it in GitHub Desktop.
<?php
function nav_element($label, $comic_url, $comic_id, $r, $desc = false)
{
if ($desc) {
$order = "pubtime DESC, id DESC";
$op = "<";
} else {
$order = "pubtime, id";
$op = ">";
}
$query = "SELECT slug FROM ns_updates WHERE comic={$comic_id} AND published = 1 AND updtype IN (\'c\', \'i\') AND pubtime <= NOW()";
if(is_array($r)) {
$query .= " AND (pubtime {$comic_id} \"{$op}\" OR (pubtime = \"{$r['pubtime']}\" AND id {$op} {$r['id']}))";
}
$query .= " ORDER BY {$order} LIMIT 1";
$result = $conn->query($query);
if($result->num_rows) {
$arr = $result->fetch_assoc();
$current_slug = (is_array($r) ? $r['slug'] : $r);
}
if ($arr['slug'] != $current_slug) {
return "<li><a href=\"{$comic_url}/comic/{$arr['slug']}\">{$label}</a></li>";
} else {
die("I guess something went wrong");
}
}
?>
@kmelve
Copy link
Copy Markdown
Author

kmelve commented Apr 15, 2016

@kmelve
Copy link
Copy Markdown
Author

kmelve commented Apr 15, 2016

Sjekk også tenary operators.

$current_slug = (is_array($r) ? $r['slug'] : $r);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment