Anna Lord
Anna Lord

Reputation: 31

PHP - shown uploaded files repeated

I've used this code to shown uploaded files from the database, first user need to select a file name then he can see the file details ( name + size + mime..) with "download" option, the problem is this page is repeating the file details 4 times , name & size & download all repeated, whats the problem ?

here is my code

 $sql = "SELECT r.id, r.name , r.mime, r.size, r.date , s.email
          from project_report AS r
          JOIN evaluator_supervisor AS e
          JOIN student AS s      
          WHERE (s.PID = $PID AND e.EID1 = '$id' AND s.SID=r.SID) OR (s.PID = $PID AND e.EID2 = '$id' AND s.SID=r.SID) ";

$result = $dbLink->query($sql);

// Check if it was successfull
if($result) {
    // Make sure there are some files in there
    if($result->num_rows == 0) {
        echo '<p>"Sorry, No files uploaded"</p>';
    }
    else {
        // Print the top of a table
         echo '<center>';
        echo '<table width="90%">
                <tr>
                    <td><b>Name</b></td>

                    <td><b>Mime</b></td>
                    <td><b>Size (bytes)</b></td>
                    <td><b>Date</b></td>
                    <td><b>&nbsp;</b></td>
                    <td><b>Feedback</b></td>
                </tr>';

        // Print each file
        while($row = $result->fetch_assoc()) {
            echo "
                <tr>
                    <td>{$row['name']}</td>

                    <td>{$row['mime']}</td>
                    <td>{$row['size']}</td>
                    <td>{$row['date']}</td>
                    <td><a href='Download.php?id={$row['id']}'>Download</a></td>
                    <td><a href='messege2.php?id={$row['email']}'><img src='mail2.gif'/></a></td>
                </tr>";
        }

        // Close table
        echo '</table>';
         echo '</center>';
    }

Upvotes: 0

Views: 76

Answers (2)

Del Pedro
Del Pedro

Reputation: 1213

Add GROUP BY r.id to your mysql query?

EDIT:

Your query does not contain any condition how to join evaluator_supervisor AS e.

Upvotes: 1

gd1
gd1

Reputation: 11403

Please ensure your SQL query does not produce duplicate tuples for some values of $id and $PID. This may happen, for example, if there are more than one "evaluator_supervisor" for a single "project_report".

Try the query outside the program, manually.

I don't know the structure of the tables, so I don't get the full logic of your query: you better figure out yourself or post it here.

Upvotes: 0

Related Questions