I have a system to show health tips. I would like the next or previous click to change to the next tip that is contained in the database.
I have already managed to generate a value that is a number less or more than the ID of each council but I do not know how to change it where the ID is.
Index.php
<?php
include "conexion.php";
include "funciones/obtener.php";
$datos = obtenerPrimerRegistro();
$nume_cons = $datos["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='funciones/contador.php?contador=1&nume_cons=<?=$nume_cons;?>'" value='Anterior'></td>
<td><input type="button" onclick="location.href='funciones/contador.php?contador=2&nume_cons=<?=$nume_cons;?>'" value="Siguiente"></td>
<td><input type="button" onclick="location.href='funciones/opciones.php?opcion=1&nume_cons=<?=$nume_cons;?>'" value="Descargar"></td>
<td><input type="button" onclick="location.href='funciones/opciones.php?opcion=2&nume_cons=<?=$nume_cons;?>'" value="Favorito"></td>
<td><input type="button" onclick="location.href='funciones/opciones.php?opcion=3&nume_cons=<?=$nume_cons;?>'" value="???"></td>
</tr>
</table>
</body>
</html>
Get.php
<?php
require_once "./conexion.php";
function obtenerPrimerRegistro(){
global $cone;
$consejos= mysqli_query($cone,"SELECT nume_cons,titu_cons,desc_cons FROM CONSEJO");
$registro= mysqli_fetch_array($consejos);
return array("nume_cons"=>$registro["nume_cons"],"titu_cons" => $registro["titu_cons"], "desc_cons" => $registro["desc_cons"]);
}
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;
}
?>
contador.php
$contador=$_REQUEST["contador"];
$nume_cons=$_REQUEST["nume_cons"];
if ($contador == 1){
$new=$nume_cons-1;
echo $new;
echo "<script> location.href='../index.php?nume_cons=$new' </script>";
}
else if ($contador==2){
$new=$nume_cons+1;
echo $new;
echo "<script> location.href='../index.php?nume_cons=$new' </script>";
}
?>