简体   繁体   中英

PHP MYSQL display table with action row clickable to open specific file

I am having this type of problem. I have a table displayed on my webpage. Wherein I have an Action column. I am trying to make my (a href) code open different files depending on what was indicated on my table whether it is pdf or an excel file.

<?php
    $con=mysqli_connect("localhost","root","","annualdb");
    // Check connection
    if (mysqli_connect_errno())
    {
        echo "Failed to connect to MySQL: " . mysqli_connect_error();
    }

    $result = mysqli_query($con,"SELECT * FROM aviation_report");

    echo "<head><style>
    table {
        border: 2px solid black;
        width: 100%;
        height: 100px;
        text-align: center;
    }

    </style></head>";
    echo "<table>
    <tr>
    <th>Agency</th>
    <th>FileName</th>
    <th>FileType</th>
    <th>Date</th>
    <th>Action</th>
    </tr>";

    while($row = mysqli_fetch_array($result))
    {
        echo "<tr>";
        echo "<td>" . $row['agency'] . "</td>";
        echo "<td>" . $row['filename'] . "</td>";
        echo "<td>" . $row['filetype'] . "</td>";
        echo "<td>" . $row['date'] . "</td>";
        echo "<td><a href='sample.pdf'>OPEN FILE</a></td>";
        echo "</tr>";
    }
    echo "</table>";

    mysqli_close($con);
?>

You would have this code:

while($row = mysqli_fetch_array($result))
{
    echo "<tr>";
    echo "<td>" . $row['agency'] . "</td>";
    echo "<td>" . $row['filename'] . "</td>";
    echo "<td>" . $row['filetype'] . "</td>";
    echo "<td>" . $row['date'] . "</td>";
    echo "<td><a target='_blank' href='" . $row['filename'] . "'>OPEN FILE</a></td>";
    echo "</tr>";
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM