View the details of an employee

0

I have a database of employees, with a search form, search the user says the name, surname, photo and the position. I have below the names of the employees and I want them to click on a page with their details (Name, Surname, position and photo) when they click on it.

this is my query to see the details

emp_detalles.php

<div id="content">

    details view.
<?php

$user = "root"; 
$password = ""; 
$host = "localhost"; 
$dbase = "employees_assign"; 
$table = "tbl_employees";

$connect = new mysqli($host, $user, $password, $dbase);
$sql = ("SELECT * from tbl_employees");
$emp= $connect->query($sql);


echo '<li id="names"><a href="index.php?id='.$emp['emp_id'].'">'.$emp['emp_fname'].' '.$emp['emp_lname'].' '.$emp['emp_lname'].' </a></li>';



?>

</div>

But he tells me that

details view. 
Fatal error: Uncaught Error: Cannot use object of type mysqli_result as array in C:\wamp64\www\employees_done\views\emp_detail.php:18 Stack trace: #0 {main} thrown in C:\wamp64\www\employees_done\views\emp_detail.php on line 18

I have tried in all ways, and I have not been able to give me the details.

I appreciate the attention

    
asked by Bella 02.12.2017 в 09:54
source

1 answer

0

What the error says is that you can not treat an object of type mysqli_result as an array:

I understand that this $emp['emp_id'] should be rewritten so $emp->emp_id

But how can you return more than one employee:

<div id="content">

    details view.
    <?php

    $user = "root";
    $password = "";
    $host = "localhost";
    $dbase = "employees_assign";
    $table = "tbl_employees";

    $connect = new mysqli($host, $user, $password, $dbase);
    $sql = ("SELECT * from tbl_employees");

    $empleados = $connect->query($sql);

    foreach ($empleados as $empleado) {
        echo '<li id="names"><a href="index.php?id=' . $empleado->emp_id . '">' . $empleado->emp_fname . ' ' . $empleado->emp_lname . ' ' . $empleado->emp_lname . ' </a></li>';
    }

    ?>

</div>
    
answered by 02.12.2017 в 10:02