List data only for a given ID

Asked

Viewed 795 times

-1

I made a small system where the administrator "sends" documents to a particular user, where it sends the info to a BD and generates a folder with the user ID. In the image below is the BD responsible for saving the information of the uploaded files, such as: URL, File Name, Description and the user ID to which the file was sent, which is in the table Identification.

Imagem do Banco de Dados onde fica gravado os dados dos arquivos enviados.

When the client accesses your administrative part, I want to list the documents that have the same ID as him, in case compare the SESSION ID and List the documents that have the same ID.

Below the page where lists the documents, but not in the way I want, because I can not put the link to download and nor description.

require_once 'conexao.php';
include("includes/header.php");  
$query = mysql_query("SELECT * FROM usuarios WHERE usuario = '$_SESSION[usuario]' AND senha = '$_SESSION[senha]'") or die(mysql_error());
$cliente = mysql_fetch_assoc($query);

$query = mysql_query("SELECT nome,url FROM arquivos") or die(mysql_error());
$arquivos = mysql_fetch_assoc($query);
$urlbd = $arquivos['url'];
$id = $cliente['id'];
$nome = $arquivos['nome'];
$dir = "../../restrito/adm/uploads/$id";
$url = "../../restrito/adm/uploads/$id/$nome";
$pasta = opendir($dir);
/* Loop para ler os arquivos do diretorio */
while ($arquivo = readdir($pasta)){
    /* Verificacao para exibir apenas os arquivos e nao os caminhos para diretorios superiores */
    if ($arquivo != '.' && $arquivo != '..'){
        /* Escreve o nome do arquivo na tela */
        echo "<a href='$urlbd' target='_blank'>$arquivo</a><br>";
    }
}

1 answer

0

Try this:

require_once 'conexao.php';
include("includes/header.php");

$result = mysql_query("SELECT nome, url FROM arquivos WHERE identificacao = {$_SESSION['usuario']}") or die(mysql_error());
while ($arquivos = mysql_fetch_assoc($result)) {
    $urlCompleta = "../../restrito/adm/{$arquivo['url']}"; 
    echo "<a href='$urlCompleta' target='_blank'>{$arquivo['nome']}</a><br>";
}

This should display the name of each file that is in the database and was sent to the session user. I’m assuming the session user index contains the user id.

A hint: don’t use functions mysql_*. Use PDO or some database abstraction framework, such as Doctrine.

And when you need to print the value of an array element into a string, you need to put the variable between keys.

Browser other questions tagged

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