I have a question about how to limit the options that a user sees in a form in my select / option
I want the user id = 1 to only see the clients that I assign (let's say the client1 and clients5)
I am free to add fields for this purpose in my database users and clients which are: < br>
users
id nombre usuario contraseña tipoUsuario
1 Miguel us1 psw1 1
2 Pedro us2 psw2 1
3 Lalo us3 psw3 2
4 Juan us4 psw4 2
5 Diego us5 psw5 3
clients
idCliente cliente
1 cliente1
2 cliente2
3 cliente3
4 cliente4
5 cliente5
My intention is that they can see in my meeting only their assigned clients.
I'm using a Select field where I show all the clients in the clients table:
<?php
$conn //aqui tengo la conecion a la base de datos
session_start();
include "../controler/conn.php";
if (!isset($_SESSION['user_log'])&& $_SESSION['user_log']==null) {
header("location: ../action/logout.php");
}
$id=$_SESSION['user_log'];
$query=sqlsrv_query($conn,"SELECT * from usuarios WHERE correo='$id'");
while ($row=sqlsrv_fetch_array($query)) {
$tt_usuario_id = $row['id']; //el id del usuario
?>
<select name="cliente" >
<option value="" >--Select--</option>
<?php
$sqlCliente = "SELECT * FROM clientes";//aqui es donde agregaria el where
$resultCliente = sqlsrv_query($conn,$sqlCliente);
while($rowCliente = sqlsrv_fetch_array($resultCliente) )
{
$idClienteSelect= utf8_encode($rowCliente['idCliente']);
$clienteSelect = utf8_encode($rowCliente['cliente']);
?>
<option value ="<?php echo $idClienteSelect;?>">
<?php echo $clienteSelect;?>
</option>
<?php } ?>
</select>
As I mentioned, I would like to know what would be a good method in my where or what to add in the database to assign clients to the users and be able to show only what was assigned (I have been tried but I think that the ideas were finished: ))