I am trying to create next and previous buttons on a page. I am using the id to call the information from the database and also using the id variable to choose the new and previous row.
It works for the next button, but the previous button keeps returning an id of 1.
This is my function in php:
function getNavLinks($subj) {
global $connection;
$query = "SELECT
( SELECT id FROM artists WHERE id > " . $subj . " LIMIT 1 )
AS nextValue,
( SELECT id FROM artists WHERE id < " . $subj . " LIMIT 1 )
AS prevValue
FROM artists";
$result_set = mysql_query($query, $connection);
confirmQuery($result_set);
//if no rows are returned, fetch array will return false.
if ($Links = mysql_fetch_array($result_set)) {
return $Links;
}
else {
return NULL;
}
}
and I am calling it in the html head like this:
<?php
$subj = $_GET['subj'];
$navLink = getNavLinks($subj);
?>
and in the body like this:
<?php echo "<a href=\"artist.php?subj=" . urlencode($navLink['prevValue']) . "\">Prev</a>"; ?>
<?php echo "<a href=\"artist.php?subj=" . urlencode($navLink['nextValue']) . "\">Next</a>"; ?>
Why is the $navLink[‘prevValue’] returning a value of one?
Any help would be great!
You need to change your SQL statement to this: