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 4617082
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T02:04:28+00:00 2026-05-22T02:04:28+00:00

I was asked that the output file should only output the name and id

  • 0

I was asked that the output file should only output the name and id of the last person who uploaded a file with a specific name. confusing right? even I am confused. so let me give an example

let us say that you have 3 employees registered in your company. lets call them

  1. Pikachu,
  2. Raichu and
  3. Pichu.

Pikachu has 3 files uploaded in the company, Raichu has 2 files uploaded and Pichu has also 2 files uploaded. The files must also be ordered according to employeename(ASC) and filename(DESC). Mine is already in ordered by. This is my only problem. In this case the output should look like this:

*noticed that the employee name and employee id is in the last file uploaded?? does anyone knows how to do that?please i beg you guys to help me out here T-T the task is way too hard and im just a rookie

Im thinking of using 2 tables here. table 1 for the employee id and employee name, table 2 for the file name, etc. so i guess this would also involve 2 while clause. i have the idea but i dont know how to mix them all up.

my code before I edited it like sir vincent look like this:

if ($_SESSION[$fgmembersite->GetLoginSessionVar()] == 'sa' 
   OR $_SESSION[$fgmembersite->GetLoginSessionVar()] == 'admin')
{                                   

  $sql= "select * from gmdc_employee 
         where employee_name like '%$search%' 
         AND employee_name like '$listname%'";
} else {
  $sql = "select b.* from gmdc_user a, gmdc_employee b 
          where a.username = '".$_SESSION[$fgmembersite->GetLoginSessionVar()]."' 
          AND a.company_id = b.company_id 
          AND b.employee_name like '$listname%' 
          AND b.employee_name like '%$search%'"; 
}
$query = mysql_query("$sql ORDER BY employee_name,confirmation DESC 
                     ,file_id DESC,file_date DESC 
                      LIMIT $offset,$limit") or die ( mysql_error () );
$result = mysql_query($sql) or die (mysql_error());
$total = mysql_num_rows($result);

if(!$result || mysql_num_rows($result) <= 0)
{
  $fgmembersite->HandleError("No file found.");
  return false;
}
while ($row = mysql_fetch_assoc($query))
{
  $file_id = $row['file_id'];
  $file_desc = $row['file_description'];
  $file_date = $row['file_date'];
  $file_name = $row['file_name'];
  $file_accs = $row['folder_access'];
  $file_employee  = $row['employee_id'];
  $file_confir = $row['confirmation'];
  $file_ename = ucwords($row['employee_name']);

  $info = pathinfo($file_name);
  $file_ext = $info['extension'];

  echo '<tr><td>&nbsp;</td></tr>
        <tr class="subone"><td class="sub" width="100">'.$file_employee.'<br />
        &nbsp;</td>';
  if($_SESSION[$fgmembersite->GetLoginSessionVar()] == 'sa')
  {
    ?>
    <td class="sub" width="100">
    <a href="" onclick = javascript:newPopup('addfile.php?emp=
    <?php echo $file_employee ?>');><?php echo$file_ename?></a>
    <br />&nbsp;</td>
    <?php
  } else {
    echo '<td class="sub" width="182">'.$file_ename.'<br />&nbsp;</td>';
  }
  echo'<td  class="sub" width="218">
       <a href="'.$file_accs.$file_name.'" target="_blank" 
        style="text-decoration: underline;">'.$file_desc.'</a>
       <br />&nbsp;</td><td  class="sub" width="100">
      '.date('M d, Y',mktime(0,0,0,substr($file_date,5,2)
       ,substr($file_date,8,2),substr($file_date,0,4))).'
       <br />&nbsp;</td><td  class="sub" width="100">'.$file_confir.'
       <br />&nbsp;</td>';

  if($_SESSION[$fgmembersite->GetLoginSessionVar()] == 'sa')
  {
    if($file_confir == 'Pending' OR $file_confir == 'NotApproved')
    {
      if(isset($_GET['id']))
      {
        $fgmembersite->Delete_Db($_GET['id']);
      }
      echo '<td  class="sub" width="100">
            <a href="index.php?id='.$file_id.'">Delete</a>
            <br />&nbsp;</td>';
    }
  }
  else if($_SESSION[$fgmembersite->GetLoginSessionVar()] == 'admin')
  {
    if($file_confir == 'Pending')
      {
        if(isset($_GET['yes']))
        {
          $fgmembersite->UpdateYesDB($_GET['yes']);
          //echo "<script>location.reload();</script>";
        }
        else if(isset($_GET['no']))
        {
          $fgmembersite->UpdateNoDB($_GET['no']);
          //echo "<script>location.reload();</script>";
        }
        if (!isset($_GET['offset'])) {
          $prevoffset = 0;
        } else {
          $prevoffset = $_GET['offset'];
          echo'<td  class="sub" width="100">
          <a href="index.php?offset='.$prevoffset.'&searchfile='.$search.'
           &namelist='.$listname.'&yes='.$file_id.'">Approve</a>
           //there's a link here<br /><br />
           <a href="index.php?offset='.$prevoffset.'&searchfile='.$search.'
            &namelist='.$listname.'&no='.$file_id.'">NotApprove</a>
            //there's a link here
            &nbsp;</td> ';
      }
    }
  }?>

Just ignore every if($_SESSION[$fgmembersite->GetLoginSessionVar()] == 'admin') and whatever, this is for different output since my file can be logged into by 3 different users. SA(programmers), admin(the approver of the file uploaded), and user(company). There are TD and TR there as well, I don’t know why wont it appear here.

output looked like this:

employee_id  +   employee_name  +  file_name
3            |   pichu          |  file6
3            |   pichu          |  file1
1            |   pikachu        |  file7
1            |   pikachu        |  file4
1            |   pikachi        |  file3
2            |   raichu         |  file8
2            |   raichu         |  file5
2            |   raichu         |  file2

and I want my output to be like this:

***OUTPUT***

**employee_id        employee_name              file_name**
    3                      pichu                        file6
                                                        file1
    1                     pikachu                       file7
                                                        file4
                                                        file3
    2                     raichu                        file5
                                                        file2

for example that raichu uploaded another file, the output should now look like this:

OUTPUT

**employee_id        employee_name            file_name**
    3                      pichu                      file6
                                                      file1
    1                      pikachu                    file7
                                                      file4
                                                      file3
    2                      raichu                     file8
                                                      file5
                                                      file2
  • 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-05-22T02:04:29+00:00Added an answer on May 22, 2026 at 2:04 am

    Using Vincent table structure will likely solve your problem. And to get the result you wanted, you can use single query using join for the two table. So there’s no need to use two query.

    SELECT  e.employee_id as employee_id,            //Display column for employee_id
            e.employee_name as employee_name,        
            f.file_name as file_name
      FROM employee e                                // The e is an alias for table
     INNER JOIN file f                               // The inner join will return all the rows which have same employee_id on both table 
        ON e.employee_id = f.employee_id
     ORDER BY e.employee_name, f.file_name DESC;     // Order of the result default is ASC
    

    UPDATE

    I assume you have two tables and the structure is same with Vincent. Now This query will get the data on two tables. The join part here is that, when an employee_id on employee table has a same employee_id on the file table, this will return a row. Please see mysql join for more information. Then the order e.employee_id is the employee_id on employee table, since there’s no order specified it will use the default which is ascending.

    Then output of the above query could be the below code.

    employee_id  +   employee_name  +  file_name
    3            |   pichu          |  file6
    3            |   pichu          |  file1
    1            |   pikachu        |  file7
    1            |   pikachu        |  file4
    1            |   pikachi        |  file3
    2            |   raichu         |  file8
    2            |   raichu         |  file5
    2            |   raichu         |  file2
    

    You will notice that employee_id and employee_name is repeated. This is because the query include all the columns value in a row that specified in SELECT column_name. You can filter the duplicate value in your php, specially if you will store it first in an object rather than directly printing it.

    PHP

    $query = $see_the_query_above;
    $result = mysql_query($query) or die(mysql_error($db));
    $emp_id = "";     //This will be use to remove employee_id if its already echoed.
    $emp_name = "";   //This will be use to remove employee_name if its already echoed.
    
    echo '<table>';
    echo '<tr><th>employee_id</th><th>employee_name</th><th>file_name</th></tr>';
    
    while ($row = mysql_fetch_assoc($result)) {
        //Check $emp_id and $emp_name if same with the current, if same just print nothing or space else replace it with new.
        $emp_id = $emp_id == $row['employee_id'] ? "" : $row['employee_id']
        $emp_name = $emp_name == $row['employee_name'] ? "" : $row['employee_name'];
    
        echo '<tr>';
        echo '<td>'.$emp_id.'<td>';
        echo '<td>'.$emp_name.'</td>';
        echo '<td>'.$row['file_name'].'</td>';
        echo '</tr>';
    }
    echo '</table>';
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

A person (a senior citizen who is learning the very basics of computers) asked
I've been asked to output a CSV file from a view in MySQL. The
I've been asked to prototype a replacement file transformation process (that currently is a
I'm the same guy that asked: BEGIN/END and CREATE Table in single .sql file
I'm re-casting a question I asked earlier now that I have an idea of
So, as per a separate question that I asked I'm using the following code
I know that similar questions might be asked a number of time but it
I asked a similar question yesterday that was answered correctly. SQL requiring self join
I know that this has already been asked here but the answer (using a
I realize that this question has been asked 100times but none that I have

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.