I have a system that shows "TIPS" of health contained in a database. I would like to add buttons next and previous
The idea is that when you press next or previous one, change the nume_cons and then load the title, the description and the image ( obtain.php )
CURRENTLY THE PROBLEM IS THAT: IT ONLY INCREASES THE VALUES WHEN PRESSING NEXT DOES NOT RETROFECT THE PREVIOUS:
INDEX
<?php
include "conexion.php";
include "funciones/obtener.php";
//include "funciones/cargar.php";
if (!isset($_REQUEST["nume_cons"])){
$_REQUEST["nume_cons"] = 0;
}else{
if (!is_numeric($_REQUEST["nume_cons"])){
$_REQUEST["nume_cons"] = 0;
}
}
$nume_cons = $_REQUEST["nume_cons"];
if (!is_numeric($nume_cons)){
$nume_cons = 0;
$anterior=0;
}else{
$anterior = $nume_cons++;
echo "anterior";
}
$siguiente = $nume_cons--;
echo "siguiente";
//-- obtenemos los datos
$datos = obtenerRegistro($nume_cons);
$titu_cons = $datos["titu_cons"];
$desc_cons = $datos["desc_cons"];
?>
<!DOCTYPE HTML>
<html>
<head>
<meta utfset="utf-8">
<link rel="stylesheet" type="text/css" href="css/estilos.css">
</head>
<title>TuSalud</title>
<body>
<h1> TuSalud... Un consejo a la vez </h1>
<table>
<tr>
<td colspan="5"> <input type="text" id="nume_cons" name="nume_cons" value="<?php echo $nume_cons;?>"></td>
</tr>
<tr>
<td colspan="5"> <input type="text" id="titu_cons" name="titu_cons" value="<?php echo $titu_cons;?>"></td>
</tr>
<tr>
<td colspan="5"> <img src="<?php echo obtenerImag($nume_cons);?>"> </td>
</tr>
<tr>
<td colspan="5"> <input type="text" id="desc_cons" name="desc_cons" value="<?php echo $desc_cons;?>"></td>
</tr>
<tr>
<td><input type="button" onclick="location.href='index.php?nume_cons=<?=$anterior;?>'" value="Anterior"></td>
<td><input type="button" onclick="location.href='index.php?nume_cons=<?=$siguiente;?>'" value="Siguiente"></td>
</tr>
</table>
</body>
</html>
Get data:
<?php
require_once "./conexion.php";
function obtenerRegistro($nume_cons){
global $cone;
$consejos= mysqli_query($cone,"SELECT titu_cons,desc_cons FROM CONSEJO WHERE nume_cons=$nume_cons");
$registro= mysqli_fetch_array($consejos);
return array("titu_cons" => $registro["titu_cons"], "desc_cons" => $registro["desc_cons"]);
}
function obtenerImag($nume_cons){
global $cone;
$imagen= mysqli_query($cone,"SELECT nume_imag FROM CONSEJO WHERE nume_cons=$nume_cons");
$img= mysqli_fetch_array($imagen);
$nume_imag=$img["nume_imag"];
$ruta_imag="./recursos/imagenes/imagen".$nume_imag.".jpg";
return $ruta_imag;
}
?>