+1
Esto te podría ayudar a conseguir lo del ejemplo #2: y le agregué un par de mejoras también:
function TituloAnterior() {
$post_id = intval($_GET['post_id']) - 1;
if($post_id <= 0) return false;
$query = db_exec(array(__FILE__, __LINE__), 'query', 'SELECT post_id, post_title FROM p_posts WHERE post_id = \''.(int)$post_id.'\' LIMIT 1');
if(db_exec('num_rows', $query) == 0) {
$query = db_exec(array(__FILE__, __LINE__), 'query', 'SELECT post_id, post_title FROM p_posts WHERE post_id < \''.(int)$post_id.'\' ORDER BY post_id DESC LIMIT 1');
}
$data = db_exec('fetch_assoc', $query);
return (!empty($data) ? $data['post_title'] : false);
}
function TituloSiguente() {
global $tsCore;
$post_id = intval($_GET['post_id']) + 1;
if($post_id <= 0) return false;
$query = db_exec(array(__FILE__, __LINE__), 'query', 'SELECT post_id, post_title FROM p_posts WHERE post_id = \''.(int)$post_id.'\' LIMIT 1');
if(db_exec('num_rows', $query) == 0) {
$query = db_exec(array(__FILE__, __LINE__), 'query', 'SELECT post_id, post_title FROM p_posts WHERE post_id > \''.(int)$post_id.'\' ORDER BY post_id ASC LIMIT 1');
}
$data = db_exec('fetch_assoc', $query);
return (!empty($data) ? $data['post_title'] : false);
}
Espero te sirva, al principio lo hice con un loop pero es mucho mejor con SQL.