assign selected href to a php variable

0

the next function what it does is search for a typed word and show me the possible matches (search engine). When I show the matches I am doing it through a href and I would like to store the href in a php variable, to keep the searches that are made. My idea is to use the options where the user clicks, but there may be several options, not just one.

<?php 
if(!isset($_POST['search'])) exit('No se recibió el valor a buscar');

require_once 'conexion.php';

function search()
{
  $mysqli = getConnexion();
  $search = $mysqli->real_escape_string($_POST['search']);
  $query = "SELECT sintomas_resp FROM sintomas WHERE sintomas_resp LIKE '%$search%' ";
  $res = $mysqli->query($query);
  while ($row = $res->fetch_array(MYSQLI_ASSOC)) {
    echo "<p><a href='#'>$row[sintomas_resp]</a></p>";
  }
}

search();
    
asked by juancamilovallejos0 25.05.2018 в 17:21
source

1 answer

0

You just have to declare the variable out of the while and print it at the end ...

<?php 
if(!isset($_POST['search'])) exit('No se recibió el valor a buscar');

require_once 'conexion.php';

function search()
{
  $mysqli = getConnexion();
  $search = $mysqli->real_escape_string($_POST['search']);
  $query = "SELECT sintomas_resp FROM sintomas WHERE sintomas_resp LIKE '%$search%' ";
  $res = $mysqli->query($query);
  $Listado = "";
  while ($row = $res->fetch_array(MYSQLI_ASSOC)) {
    $Listado = $Liestado . "<p><a href='#'>$row[sintomas_resp]</a></p>";
  }
  echo ($Listado); 
}

search();
    
answered by 27.05.2018 / 04:05
source