Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8504061
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T01:55:24+00:00 2026-06-11T01:55:24+00:00

I am trying to combine 2 tables from my database: files table: id file_name

  • 0

I am trying to combine 2 tables from my database:

files table:

    id
    file_name
    file_description
    file_url

access_files table:

    id
    student_id
    file_id

Here is my sql code, currently getting all files from the files table, it doesn`t show the selected files for the user.

<?php
    $SQL = "SELECT * FROM files, access_files WHERE student_id ='$studentid'";
    $result = mysql_query($SQL);

    while ($db_field = mysql_fetch_assoc($result)) {
?>                          

<div class="accordion-group">
<div class="accordion-heading">
    <a href="#<?php print $db_field['file_id']; ?>" data-parent="#accordion" data-toggle="collapse" class="accordion-toggle collapsed">
    <?php print $db_field['file_name']; ?>
    </a>
</div>
<div class="accordion-body collapse in" id="<?php print $db_field['file_id']; ?>">
    <div class="accordion-inner">
    <?php print $db_field['file_description']; ?><br/><br/>
    <a href="?download=<?php print $db_field['file_url']; ?>" class="more">Download File Now!</a>
    <br/><br/>
    </div>
</div>
</div>
<?php } ?>

The code is suppose to show only the files associated to the user.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T01:55:25+00:00Added an answer on June 11, 2026 at 1:55 am

    What you need to do is JOIN the tables.

    Most common types of JOINs:

    1. INNER JOIN – Used to match data where it can match the ON () statement. If the ON() doesn’t match, the result will be excluded.
    2. LEFT JOIN – Used if the data you match in the ON() doesn’t have to be there. It just appends the data to the original FROM, and fills columns with NULL if no data is matched.

    Example

    SELECT
     ft.id,
     ft.file_name,
     ft.file_description,
     ft.file_url,
     af.id as access_id,
     af.student_id,
     af.file_id
    FROM
     files ft
     INNER JOIN access_files af ON ( ft.id = af.file_id )
    WHERE
     fa.student_id = '$studentid'
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to combine data from two tables in MySQL with PHP. I want
I have two tables from two different databases. For example: Table: Articles1 - Database:
I'm trying to remove an association table from my database. It contains two columns
Basically I'm trying to combine two tables together into a new table. The first
I'm trying to combine the data in two tables. The first (child) table contains
I have a mysql query that is trying to combine the following tables: TABLE:
I'm working on a project where I'm trying to combine three different tables. Table
I'm trying to combine to two tables, and I want the smallest id where
I'm trying to combine multiple files in multiple input directories into a single file,
I'm trying to combine all javascript files in a project during the build process,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.