Being Able to Show a User’s Products

Asked

Viewed 59 times

3

Good!

The thing is, I’m developing a website that consists of a user seeing the condition of their device while it’s being repaired. But I’m having a hard time visualizing a certain user’s product for him.

For example: The administrator inserts a product into the database with a certain ID, and then the customer logs into the website and should be able to view your product...

I created the following tables -> Users, Equipment and user_equipment.

Here’s what I did:

Dataacess.php ( Serves to connect the database )

Function to fetch records:

function getRegistos(){

    $query = "SELECT *, DATEDIFF(NOW(),dataDeEntrada) as diferenca FROM `equipamentos` WHERE 1";
    $this->connect();
    $res = $this->execute($query);
    $this->disconnect();
    return $res;

}

Function to insert record

function inserirRegisto($id_utilizador, $nome, $tipo, $estado, $marca, $modelo, $sintoma, $orcamento) {
        $query = "insert into equipamentos 
                    (id_utilizador, nome, tipo, estado, marca, modelo, sintoma, orcamento)
                    values 
                    ('$id_utilizador', '$nome','$tipo','$estado','$marca', '$modelo','$sintoma','$orcamento')";
        $this->connect();
        $this->execute($query);
        $this->disconnect();
}

And then to get the records I did this:

$id = $_SESSION['id'];
include_once('DataAccess.php');
$da = new DataAccess();
$res = $da->getEquipamento($id);
while($row = mysqli_fetch_object($res)){ ... }

I need to get all the equipment of a certain user by their ID, but I don’t know how I can do it. I know the user_equipment table will help me but I still don’t know how.

1 answer

3


It would be easier if you associated a user with each piece of equipment. Add the field user_id to the equipment table:

insert into equipamentos 
            (nome, tipo, estado, marca, modelo, sintoma, orcamento, user_id) ...

And then just do the SELECT thus:

$query =
"SELECT *, DATEDIFF(NOW(),dataDeEntrada) as diferenca ".
"FROM `equipamentos` ".
"WHERE user_id='$id_utilizador'";

Browser other questions tagged

You are not signed in. Login or sign up in order to post.