I am trying to work out how to get data from two different tables in the same database and retrieve the filenames uploaded into the database for a specific ticket id and username. I have been having a go at the php code myself and have managed to INNER JOIN the two tables but on the php page, it's showing all the uploaded files for the specific user instead of just for the specific ticket id and username together and looks like it's looping through and repeating. Below is the code I have currently have

<?php
                                                        $con = mysqli_connect("localhost","dbuser","dbpass","dbname");
                                                        if (mysqli_connect_errno()) {
                                                        echo "Unable to connect to MySQL! ". mysqli_connect_error();
                                                        }
                                                        $sqli = "SELECT support_tickets.ticket_id, support_ticket_files.file_name, support_tickets.user_name FROM support_tickets INNER JOIN support_ticket_files ON support_tickets.user_name=support_ticket_files.user_name
WHERE support_tickets.ticket_id = 'ticket_id' AND support_tickets.user_name = '".$_SESSION["user_name"]."'";
                                                        $res = mysqli_query($con, $sqli);
                                                        while ($row = mysqli_fetch_array($res)) {
                                                        echo "<ul class='nav'>";
                                                        echo "<li><a href='".$row['file_name']."' class='noline'>Download</a></li>";
                                                        }
                                                        mysqli_close($con);
                                                        ?>

I have just managed to solve it by updating the query to the following

SELECT support_tickets.ticket_id, support_ticket_files.file_name, support_tickets.user_name FROM support_tickets INNER JOIN support_ticket_files ON support_tickets.user_name=support_ticket_files.user_name
    WHERE support_tickets.ticket_id = ".$_GET['ticket_id']." AND support_tickets.user_name = '".$_SESSION["user_name"]."'
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.