List data only for a given ID

-1

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

Whentheclientaccessesyouradministrativepart,IwanttolistthedocumentsthathavethesameIDofthesame,inthecaseofcomparingtheSESSIONIDandListdocumentsthathavethesameID.

Belowthepagewhereyoulistthedocuments,butnotthewayIwantthem,becauseIcannotputthedownloadlinkordescription.

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>";
    }
}
    
asked by anonymous 07.03.2016 / 01:55

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 sent to the session user. I'm assuming that the 'user' index of the session contains the user id.

One tip: do not use mysql_* functions. Use PDO or some database abstraction framework, such as Doctrine.

And when you need to print the value of an element of an array in a string, you need to put the variable in braces.

    
07.03.2016 / 02:29