Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.5k views
in Technique[技术] by (71.8m points)

html - echo problems in PHP

I dont know how to repost questions so im just gonna link my old post here some item won't echo after putting some condition in php

although some problems were solved there thanks to @Shinkou, there are still errors found in my program.I tried to figure out what caused this problem but i found no luck in solving them.


now let me tell you what my program does.i have 2 admins with different functions. the admin uploads file,and registers a new company and employee detail.he is also responsible for deleting the not approved or pending files.(NO PROBLEMS HERE ^_^) the 2nd one is superadmin. its purpose is to view uploaded files and approve or reject the file uploaded. (AS YOU SEE, ITS ALL ABOUT THE FILES UPLOADED BY THE ADMIN) the other user are the company account.this account is created when the admin registers a new company.Its purpose is just for viewing which file have been approved or rejected by the superadmin.

my problem is all in the superadmin and other user.but lets talk about the superadmin more.my superadmin contains 3 menubars(i used link images here-working)->HOME(to view all accepted/rejected files),NEW UPLOAD(to view and accept/reject all pending files)and LOGOUT.the NEWUPLOAD and LOGOUT is working,but i am having problems with home and it affects the other user accounts.Lastly,code format is something like this.let me show you:


*EmployeeID*     *EmployeeName*     *Title*     *FileDate*     *Status*           

  20132248           Danica          file8     Jan 08, 2001     Approved          
  20896647           Jan             file7     Dec 12, 2000     NotApproved     
  20864125           Keisha          file2     Feb 01, 2000     Approved   
  16521253           Riorei          file10    Mar 20, 2003     NotApproved
                                     file3     Jul 14, 2002     Approved

//if you could notice employee riorei,it contains 2 files,the employeename and id will be displayed only once. this one is also already sorted as you could notice i wish.


let me list up all the problems i encountered and things i discovered as i trace the problem:

  1. an echo problem->example if riorei has 2 uploaded file, file10 and file3,if you are to accept/reject the 1st file10/file3 in the newupload,in my output,the name and id did not appear(this is what i did: i tried echoing 2 variables i used ($empid and $file_employee for id and $empname and $file_ename for name) the $empname and $empid are initialized to "" at first(i will show you the codes later)beside emmployeeid(i only tried it to id first)and this was the result i found==>the $empid that should contain a null value already contain employeeID at first wherein it should have contain that after the next loop.) BUT if you are to accept the next file.its ok >.< but i can't just leave it like that right?
  2. another thing i noticed, there are some uploaded/registered files that echoes at first loop the name and id.its like some uploaded files echo correctly while some not.
  3. The LIMIT->i put limit in my table,what i meant was,per page(yes i also created page number)only 5 files will be outputted. BUT on my page 1 it contains only 3 files,then the next page contains 1 file and so on.i also even experienced something like on the next page,there are no files uploaded but if your gonna press next again,Tadah! the file is there.(this is what i did: i put a counter to check how many times it looped in my while clause. to my shocked.it says 5!and i dont know how that happens.)

as far as i noticed,this is the only error i found. so let me show you the codes i used :)


<?php       
                            $search = '%';
                            $fgmembersite->DBLogin();
                            $limit = 5;
                            if(isset($_GET['offset'])) {
                                $offset = mysql_real_escape_string($_GET['offset']);
                            } else {
                                $offset = 0;
                            }

                            //for namelist a-z
                            $listname = '%';
                            If (isset($_GET['namelist']))
                            {                                   
                                $listname = $_GET['namelist'];
                            }

                            //for search file
                            if(isset($_POST['searchfile']))
                            {
                                $search = $_POST['searchfile'];
                            }                               
                            else if(isset($_GET['searchfile']))
                            {
                                $search = $_GET['searchfile'];
                            }

                            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%' ";                                             
                                            $sql="SELECT `e`.* FROM `gmdc_employee` `e` JOIN `gmdc_user` `u` ON ( `u`.`company_id` = `e`.`company_id` ) WHERE (`u`.`company_name` LIKE '%$search%' OR `e`.`employee_name` LIKE '%$search%' OR `e`.`employee_id` LIKE '%$search%') AND `e`.`employee_name` LIKE '$listname%' ";
                            }
                            else
                            {                                   
                                $sql = "select `e`.* from `gmdc_user` `u`, `gmdc_employee` `e` where `u`.`username` = '".$_SESSION[$fgmembersite->GetLoginSessionVar()]."' and `u`.`company_id` = `e`.`company_id` AND `e`.`employee_name` like '$listname%' AND `e`.`employee_name` like '%$search%'";                                                                                                                                 
                            }

                            $query = mysql_query("$sql ORDER BY `e`.`employee_name`, `e`.`confirmation` DESC ,`e`.`file_id` DESC,`e`.`file_date` DESC  LIMIT $offset,$limit") or die ( mysql_error () );
                            $result = mysql_query($sql) or die (mysql_error());
                            $total = mysql_num_rows($result);
                            $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.
                            $count = 0;

                            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']);

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

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

                                $count = $count + 1;
                                echo $count;

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

                                echo '<tr>
                                    <td>
                                        &nbsp; 
                                    </td>
                                    </tr>
                                    <tr class="subone">
                                    <td class="sub" width="100">
                                        ';
                                if ($file_employee == $emp_id)
                                {
                                    # do not display the employee's ID and name

                                }
                                else
                                {
                                    # display the employee's ID and name
                                    echo''.$file_employee.'';
                                }
                                        echo'<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 if ($file_ename == $emp_name)
                                            {
                                                # do not display the employee's ID and name

                                            }
                                            else
                                            {
                                                # display the employee's ID and name
                                                echo''.$file_ename.'';
                                            }?></a>
                                        <br />
                                        &nbsp;
                                    </td><?php
                                    }
                                    else
                                        {
                                            echo '<td class="sub" width="182">
                                            ';
                                if ($file_ename == $emp_name)
                                {
                                    # do not display the employee's ID and name

                                }
                                else
                                {
                                    # display the employee's ID and name
                                    echo''.$file_ename.'';
                                }
                                        echo'
                                            <br />
                                            &nbsp;
                                            </td>';
                                        }


                                    echo'<td  class="sub" width="218">
                                        <a href="'.$file_accs.$file_name.'" target=

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

I have finally discovered what went wrong with my problem. Although my codes became longer that ever.

So here's what I did, I added new query for my conditions "pending", "notapproved" and "approved" its the same query actually, i just added AND e.confirmation LIKE 'Pending' in the newupload page and AND e.confirmation LIKE 'Accepted' OR e.confirmation LIKE 'NotAccepted' in the home page. (note that i put this together with the query and created $sql2,$query2,$total2 and $result2 and since I have 1 code for page number, I already fixed that as well)

At the same time, instead of having WHILE first then If Statement, I have reversed it. And have done 2 whiles.

You could check in my codes and apply this :)

Thanks to @stefgosselin for not putting me down and the one who "ONLY" helped me in someways. I just tried it now, all i need to do now is to correct my order by. Thanks. Hope this could help others with the same problem.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...