开发者

how to echo the name and id of the last uploaded file only,the first uploaded file must not echo name and id

i would really like your help guys :( i dont really know how to do the task given to me,i tried alot of methods already but unfortunately,non of them work :(

here is that case,i was asked that the output file should only outfut 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 have 3 files uploaded in the company,raichu have 2 files uploaded and pichu have also 2 files uploaded. the files must also be ordered by 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:

***OUTPUT***

**employee_id        employee_name            file_name**
    3                   pichu                    file2

   开发者_运维问答                                              file1

    1                   pikachu                  file3

                                                 file2

                                                 file1

    2                   raichu                   file2

                                                 file1

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


***OUTPUT***

**employee_id        employee_name            file_name**
    3                   pichu                    file2

                                                 file1

    1                   pikachu                  file3

                                                 file2

                                                 file1

    2                   raichu                   file3

                                                 file2

                                                 file1

*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

big thanks to those who can help me

MisaChan


What about something like this
(Employees and files must be in two different tables)

$empsql = "SELECT id, name FROM employees ORDER BY name ASC";
$empres = mysql_query($empsql);
while($emprow = mysql_fetch_array($empres)){
    echo $emprow[name] . "<br />";
    $filsql = "SELECT name FROM files WHERE employee_id = '$emprow[id]' ORDER BY name DESC";
    $filres = mysql_query($filsql);
    while($filrow = mysql_fetch_array($filres)){
        echo $filrow[name] . " ";
    }
    echo "<br /><br /><br />";
}


i already checked my codes and there is no need to remove some codes, i just added a few lines to the code

$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.

$emp_id=$emp_id==$row['employee_id']?"":$row['employee_id'];
$emp_name=$emp_name==$row['employee_name']?"":$row['employee_name'];

and changed my echo name from employee_id to $emp_id and employee_name to $emp name :)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜