PHP中的回声问题 [英] echo problems in PHP

查看:82
本文介绍了PHP中的回声问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不知道如何转发问题,所以即时通讯链接我的旧帖子在这里
某些项目不会回应后在php中添加一些条件虽然一些问题由于@Shinkou而得到解决,但我的程序中仍然存在错误。我试图弄清楚导致这个问题,但我发现没有运气解决它们。




现在让我告诉你我的程序是干什么的。 2个管理员具有不同的功能。 admin 上传文件,并注册一个新的公司和员工详细信息,同时也负责删除未批准或挂起的文件(这里没有问题^ _ ^)第二个是 superadmin 。其目的是查看上传的文件并批准或拒绝上传的文件。 (就像你看到的那样,其所有关于管理员上传的文件)另一个用户是公司账户。当 admin 注册一家新公司时,这个账户被创建。它的目的是查看哪个文件已经被 superadmin 批准或拒绝。



我的问题全部出现在 superadmin 和其他用户中。让我们讨论一下 superadmin more.my superadmin 包含3个菜单栏(我在这里使用链接图像 - 正在工作) - > HOME(被拒绝的文件),NEW UPLOAD(查看并接受/拒绝所有待处理文件)和LOGOUT NEWUPLOAD和LOGOUT 最后,代码格式是这样的,我告诉你:




 
* EmployeeID * * EmployeeName * *标题* * FileDate * *状态*

20132248 Danica file8 Jan 08,20 01 Approved
20896647 Jan file7 2000年12月12日未批准
20864125 Keisha file2 2000年2月1日已核准
16521253 Riorei file10 2003年3月20日未核准
file3 2002年7月14日核准

//如果您注意到员工riorei,它包含2个文件,则只会显示一次employeename和id。这一个也已经排序,你可以注意到我希望。






让我列出我遇到的所有问题以及我发现的事情因为我跟踪了问题:


  1. 回显问题 - >例如,如果riorei有2个上传的文件, file10和file3 ,如果你要接受/拒绝newupload中的第一个file10 / file3,在我的输出中,名称和id没有出现(这就是我所做的:,我试着回显2个变量($ empid和$ file_employee代表id,$ empname和$ file_ename代表名称)$ empname和$ empid初始化为(稍后我会告诉你代码)emmployeeid旁边(我只试过它先识别id)这是我找到的结果==>应该包含null值的$ empid首先已经包含employeeID,其中它应该包含在下一个循环之后。)如果您要接受next file.its ok>。<但我不能像这样保留它?

  2. 另外一件事我注意到,有一些上传/注册的文件在第一个循环中回显名称和id.its,就像一些上传的文件回答正确,有些则不正确。

  3. LIMIT->我在表格中放置限制,我的意思是,每页(是的,我也创建了页码)只输出5个文件。 在我的页面1上它只包含3个文件,然后下一页包含1个文件等等。我甚至在下一页上遇到过类似情况,没有上传文件,但是如果您要按接下来,塔达! (这就是我所做的:,我把一个计数器来检查它在我的while子句中循环了多少次,让我感到震惊,我说5!我不知道这是怎么发生的。)






据我所知,这是我发现的唯一错误。所以让我告诉你我使用的代码:)






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

//用于名称列表a-z
$ listname ='%';
if(isset($ _ GET ['namelist']))
{
$ listname = $ _GET ['namelist'];


搜索文件
if(isset($ _ POST ['searchfile']))
{
$ search = $ _POST [ 'searchfile'];
}
else if(isset($ _ GET ['searchfile']))
{
$ search = $ _GET ['searchfile']; ($ _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%'或`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()]。''和'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)或die(mysql_error());
$ result = mysql_query($ sql)或die(mysql_error());
$ total = mysql_num_rows($ result);
$ emp_id =''; / /这将用于删除employee_id,如果它已经回显。
$ emp_name =''; / /这将用于删除employee_name,如果它已经回显。
$ count = 0;
$ b $ if(!$ result || mysql_num_rows($ result)< = 0)
{
$ fgmembersite-> HandleError(No file found。);
返回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;
$ b $ if($ _ SESSION [$ fgmembersite-> GetLoginSessionVar()] =='sa')
{

echo'< tr>
< td>
& nbsp;
< / td>
< / tr>
< tr class =subone>
< td class =subwidth =100>
';
if($ file_employee == $ emp_id)
{
#不显示员工的ID和姓名

}
其他
{
#显示员工的ID和姓名
echo''。$ file_employee。';
}
echo'< br />
& nbsp;
< / td>';
if($ _ SESSION [$ fgmembersite-> GetLoginSessionVar()] =='sa')
{

?>< td class =subwidth = 100 >
< a href =onclick = javascript:newPopup('addfile.php?emp =<?php echo $ file_employee?>');>
<?php if($ file_ename == $ emp_name)
{
#不显示员工的ID和名称

}
else
{
#显示员工的ID和姓名
echo''。$ file_ename。';
}?>< / a>
< br />
& nbsp;
< / td><?php
}
else
{
echo'< td class =subwidth =182>
';
if($ file_ename == $ emp_name)
{
#不显示员工的ID和姓名

}
其他
{
#显示员工的ID和姓名
echo''。$ file_ename。';
}
echo'
< br />
& nbsp;
< / td>';
}


echo'< td class =subwidth =218>
< a href ='。$ file_accs。$ file_name。'target =_ blankstyle =text-decoration:underline;>'。$ file_desc。'< / a>
< br />
& nbsp;
< / td>
< td class =subwidth =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 =subwidth =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 =subwidth =100>
< a href =index.php?id ='。$ file_id。'>删除< / a>
< br />
& nbsp;
< / td>';




$ b这是我的超级管理员和其他帐户的代码
if($ _ SESSION [ )
{
echo'< $ fgmembersite-> GetLoginSessionVar()]!='sa'&&($ file_confir =='Approved'|| $ file_confir =='NotApproved')) TR>
< td>
& nbsp;
< / td>
< / tr>

< tr class =subone>
< td class =subwidth =100>';
// echo $ emp_id .'-'。$ file_employee;
if($ file_employee == $ emp_id)
{
#不显示员工的ID和姓名
}
else
{
#显示员工的ID和姓名
echo''。$ file_employee。';
}
echo'
< br />
& nbsp;
< / td>';

echo'< td class =subwidth =182>';
if($ file_ename == $ emp_name)
{
#不显示员工的ID和姓名

}
其他
{
#显示员工的ID和姓名
echo''。$ file_ename。';
}
echo'
< br />
& nbsp;
< / td>';

echo'< td class =subwidth =218>
< a href ='。$ file_accs。$ file_name。'target =_ blankstyle =text-decoration:underline;>'。$ file_desc。'< / a>
< br />
& nbsp;
< / td>

< td class =subwidth =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 =subwidth =100>
'。$ file_confir。'
< br />
& nbsp;
< / td>';

}

$ emp_id = $ file_employee;
$ emp_name = $ file_ename;
}?>

< tr>






SORRY如果太长,它只是一些需要或询问我使用的完整代码,虽然这只是一部分。我希望有人能帮助我。 :

解决方案

我终于发现问题出在哪里,虽然我的代码变得更长了。

所以我就这样做了,我为条件pending,notapproved和approved实际添加了新的查询,我刚刚添加了 AND <$在新的上传页面中 e 。确认 LIKE'待决' e 。确认 LIKE'接受'或 e 确认 LIKE'NotAccepted'在主页中。(请注意,我把它和查询放在一起并创建了$ sql2,$ query2,$ total2和$ result2,因为我有1代码的页码,我已经修正了这一点)



与此同时,不是首先使用 ,我已将其撤销,并已完成2次。

您可以检查我的代码并应用此功能:



谢谢到@stefgosselin不会让我失望,也不会让只有帮助我。我现在就试了,现在我需要做的就是纠正我的订单了。谢谢。希望这可以帮助其他人解决同样的问题。


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="_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 
//THIS IS THE CODES OF MY SUPER ADMIN AND OTHER ACCOUNTS
if($_SESSION[$fgmembersite->GetLoginSessionVar()] != 'sa' && ($file_confir == 'Approved' || $file_confir == 'NotApproved'))
                                    {
                                        echo '<tr>
                                                <td>
                                                    &nbsp; 
                                                </td>
                                        </tr>

                                        <tr class="subone">
                                            <td class="sub" width="100">';
                                            //  echo $emp_id.'-'.$file_employee;
                                                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>';

                                            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="_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>';

                                    }

                                    $emp_id = $file_employee;
                                    $emp_name = $file_ename;
                                }?>

                            <tr>


SORRY if its too long,its just that some requires or ask the complete codes i used,although this is just part.i hope someone could help me here. :(

解决方案

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.

这篇关于PHP中的回声问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆