The file is being copied the problem is all the file is getting copied like its going through the whole loop again

<?php
    function copyfile($src,$dest){
        copy($src,$dest);
    }
?>
<!DOCTYPE html>
<html>
    <head>
        <title>Menu</title>
        <link rel="stylesheet" type="text/css" href="menu.css">
    </head>
    <body background="D:\Web\images\goo.jpg">
            <div class="header">
                <div id="logo">
                    <img src="D:\Web\images\the-library-white.png">
                </div>
            </div>
            <div class="items">
                <a href = menu.php>Browse</a> | <a href = edit.php>Edit Profile</a> | <a href = index.php>Log Out</a>
            </div>
            <div class = "list">
                <?php
                    require 'connectdb.php';
                    $result = mysql_query("SELECT * 
                                            FROM item_tbl
                                            INNER JOIN upload_tbl ON item_tbl.item_id = upload_tbl.item_id
                                            INNER JOIN item_type ON item_tbl.item_type_id = item_type.type_id
                                            WHERE upload_tbl.status =  'ACCEPTED'");
                    if (!$result) {
                    $message  = 'Invalid query: ' . mysql_error() . "\n";
                    $message .= 'Whole query: ' . $query;
                    die($message);
                    }else{

                    echo "<h1>Item List</h1><br><table border='1' align = 'center'>
                            <tr>
                            <th>Item Name</th>
                            <th>Item Type</th>
                            <th>Item Rate</th>
                            <th>Item Year</th>
                            </tr>";
                    $ctr = 0;       

                    while($row = mysql_fetch_assoc($result))
                    {
                    $file = mysql_result($result,$ctr,'location').'\\'.mysql_result($result,$ctr,'item_dlink');
                    $filename = mysql_result($result,$ctr,'item_dlink');
                    $source = 'E:\Approved\\'.$file;
                    $dest  = 'C:\Users\Dana\Desktop\\'.$filename;
                    echo "<tr align='center'>";
                    echo "<td ><a href = ".copyfile($source,$dest).">" .$row['item_name'] ."</td>";
                    echo "<td>" . $row['type_name'] . "</td>";
                    echo "<td>" . $row['item_rate'] . "</td>";
                    echo "<td>" . $row['item_year'] . "</td>";
                    echo "</tr>";
                    $ctr = $ctr + 1;
                    }
                    echo "</table>";
                    }

                ?>


            </div>
    </body>
</html>

this is what happens i get 3 items from my database and if I click one of them I download them all immediately.
I don't know whats wrong it should have only downloaded 1 item and its the one that i clicked
advice is highly appreciated

I have no idea what you are trying to achieve with the copyFile() function being used to populate the href on the anchor tag. The copyFile() function does not return a value so you are not concatenating anything. On top of that, everytime the while loop iterates you are immediatly copying the files from $src to $dest.

Are you trying to make a link that will copy/download the file when it is clicked?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.