How to view user profile?

0

Veran I have an autocomplete textbox, which is autocomplete when I'm writing from a database (Mysql). Well I want you to help me is to select the ID of those elements and go to the profile of each user that I select.

PD: They tell me that I have to create another page that is for the user profiles that I want to see. Apart from mine. Is that true?

HTML

<input type="text" id="busquedas" name="buscar" placeholder="Busca a 
alguien">             
<div id="nameList"></div>

PHP

  <?php

include("conexion.php");

 if(isset($_POST['query']))
 {

 $output = '';
 $query = "SELECT * FROM personas WHERE nombre LIKE '%". 
 $_POST['query']."%'";
 $result = mysqli_query($conn, $query);
 $output = '<ul class="list-unstyled">';

 if(mysqli_num_rows($result) > 0 )
 {

  while($row = mysqli_fetch_array($result))
  {

      $output .= '<li><a href="#">'.$row['nombre'].''.$row['apellido'].'</a>
      </li>';
   }
  }

   else
     {
    $output .= '<li>Not found</li>';
     }

     $output .= '</ul>';
     echo $output;
         }

  ?>

JQuery

 $(document).ready(function(){ 
 $('#busquedas').keyup(function(){

 var query = $(this).val();
 if(query != '')
 {
 $.ajax({

     url:"usuarios.php",
     method:"POST",
     data:{query:query},
     success:function(data)
     {
          $('#nameList').fadeIn();
          $('#nameList').html(data);
      }
    });
  }
    });

     $(document).on('click', '#nameList ul li', function(){

   $('#busquedas').val($(this).text());
    $('#nameList').fadeOut(); 
     });

  });
    
asked by luis 08.09.2016 в 04:23
source

2 answers

0

Solution ** PS: The solution was:

/*_el cual recoge el Id enviado a traves de la url_*/
$GetId = $_GET['id']; 

/*_Para hacer la seleccion de los datos segun el ID_*/
  $sql = "SELECT * FROM personas WHERE Id = '$GetId'";
  $result = mysqli_query($conn,$sql);
  $row = mysqli_fetch_array($result,MYSQLI_ASSOC);

AND THEN PICK UP OR PRINT THE DATA, BUT CLEAR EVERYTHING THAT CODE GOES ON THE USER.PHP PAGE (of the users). **

     <?php

        echo "mi Codigo es :".$GetId."<br>";
        echo "Mi nombre es :".$row['nombre']."<br>";
        echo "Mi apellido es :".$row['apellido']."<br>";
        echo "Mi correo es :".$row['correo']."<br>";
        echo "Mi clave es :".$row['password']."<br>";

        ?>

**

COMPLETE CODE **

HTML **

 <input type="text" id="busquedas" name="buscar" placeholder="Busca a 
alguien">             
 <div id="nameList"></div>

**

PHP **

 <?php

 include("conexion.php");

 if(isset($_POST['query']))
 {

 $output = '';
 $query = "SELECT * FROM personas WHERE nombre LIKE '%".  
    $_POST['query']."%'";
$result = mysqli_query($conn, $query);
$output = '<ul class="list-unstyled">';

if(mysqli_num_rows($result) > 0 )
{

    while($row = mysqli_fetch_array($result))
    {

          $output .= '<li><a href="perfil2.php? id='.$row['Id'].'">'.$row['nombre'].' '.$row['apellido'].'</a></li>';
    }
}
else
{
     $output .= '<li>Not found</li>';
}

$output .= '</ul>';
echo $output;
   }

   ?>

**

JQuery **

  $(document).ready(function(){ 
  $('#busquedas').keyup(function(){

 var query = $(this).val();
 if(query != '')
 {
 $.ajax({

     url:"usuarios.php",
     method:"POST",
     data:{query:query},
     success:function(data)
     {
          $('#nameList').fadeIn();
          $('#nameList').html(data);
     }
 });
}
    });

     $(document).on('click', '#nameList ul li', function(){

  $('#busquedas').val($(this).text());
  $('#nameList').fadeOut(); 
   });

   });

**

user.php (destination profile) **

<?php
 session_start();

 include("usuarios.php");

 $GetId = $_GET['id'];

  $sql = "SELECT * FROM personas WHERE Id = '$GetId'";
  $result = mysqli_query($conn,$sql);
  $row = mysqli_fetch_array($result,MYSQLI_ASSOC);

  ?>

<!doctype html>
<html lang="en">
<head>

</head>
<body>
<?php

        echo "mi Codigo es :".$GetId."<br>";
        echo "Mi nombre es :".$row['nombre']."<br>";
        echo "Mi apellido es :".$row['apellido']."<br>";
        echo "Mi correo es :".$row['correo']."<br>";
        echo "Mi clave es :".$row['password']."<br>";

        ?>
 </body>
 </html>
    
answered by 08.09.2016 / 22:44
source
2

Greetings, it is correct to affirm you must create a profile page, this must be reused without the need to create several profile pages per user, you only have to pass the identifier of the selected user or the identifier of your user.

In the code snippet you will have to add:

$output .= '<li><a href="perfil.php?id=23">'.$row['nombre'].''.$row['apellido'].'</a> </li>';

Where: id = 23 is the identifier of each user.

    
answered by 08.09.2016 в 06:11