无法正确回显并且循环中出现错误

发布于 2024-11-14 23:56:40 字数 587 浏览 3 评论 0原文

这是转发,我会尽可能短。 :( 但如果你想了解更多关于我的问题,这里是我上一篇文章的链接:echo issues in PHP

我的问题是,我的程序产生错误的回显结果:

1.大多数时候,它从第一次被接受时起就没有回显名称和 ID。(如果 mariel 1 下有 2 个文件,并且管理员接受了第一个(2010 年 1 月 1 日上传的示例),它应该首先回显名称和 id,然后如果第二个被接受(2010 年 2 月 2 日上传),它应该回显最后上传的文件在顶部,最后上传的文件应该有包含名称和 id,那么第一个上传的文件不得包含名称和 id,仅包含详细信息(您可能会看到链接以查看它的外观,但我的没有回显)。 2.我认为循环中存在错误。我

设置了 5 的限制来告诉程序每页只能输出 5 个数据,但我的有时输出 3 或 1 或什么也不输出(我使用计数器跟踪它,发现它仍然循环 5 次,尽管它没有回显某些内容(意味着我/超级管理员还没有接受或拒绝任何文件)

我知道这是两个不同的问题,有些可能是对此感到冒犯,但我相信这两个彼此有些关联。我希望有人可以帮助我,我真的找不到它有什么问题:(

this is a repost,i'l make it as short as possible. :( but if you want to understand more on my problem,here is the link of my previous post: echo problems in PHP

my problem is,my program is producing wrong echo result:

1.most of the times it did not echo the name and id from the 1st time it was accepted.(if there are 2 files under mariel 1,and the admin accepted the 1st one(uploaded example on jan1,2010),it should echo name and id at first,then if the 2nd one was accepted(uploaded feb 2, 2010)it should echo the last file uploaded on top where the last uploaded file should have contained the name and id,then the first uploaded file must not contain the name and id,only the details(you may see link to view what it looks like). but mine did not echo at first time a person accepts the file.

2.i think there is an error in the loop.i set a limit of 5 to tell the program that it must only output 5 data per page,but mine sometimes output 3 or 1 or nothing(in random) per page.i traced it using counter and discovered it still looped 5 times although it did not echo something(meaning i/superadmin did not accept or reject any file yet)

i know this are 2 different problems,and some might be offended by that,but i believe that these 2 is somewhat related to each other.i hope someone could help me,i really cant find whats wrong with it :(

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

习ぎ惯性依靠 2024-11-21 23:56:40

这应该是一条评论,使用问题框以获得更好的格式。

我看了一下,复制了代码并将其加载到我的编辑器中只是为了看看。

在第 31 行左右,您有这样的查询:

$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%' ";

当您 var_dump($sql) 并通过 mysql 客户端(即 phpmyAdmin)运行该查询时,此查询是否返回正确的结果?

This should be a comment, using the question box for better formatting.

I had a look at this, copied the code and loaded it in my editor just to have a look and see.

Around line 31, you have this query:

$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%' ";

Does this query return proper results when you var_dump($sql) and run that through mysql client (ie phpmyAdmin) ?

太阳男子 2024-11-21 23:56:40

第 178 行和第 194 行的这些 td 可以大大简化。

   <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 />
                
       </td>';

改用这个:

<td class="sub" width="100">';
    if ($file_employee != $emp_id)
    { 
        echo $file_employee;
    }
        echo'
        <br />
         
</td>';

注意如何使用 !运算符将语句简化了一半以上。另外,在我看来,您不需要注释来说明您正在显示 $file_employee,它不必要地使您的代码变得混乱,因为从 echo $file_employee 中可以明显看出您正在显示它。具有良好指示性变量名称的干净代码应该易于阅读,而不需要太多注释。

如果您需要注释来反映显示的变量,最好重命名该变量,这样只需查看它就可以清楚地看到。我还删除了未使用的注释代码,结果从一眼难以理解变为一目了然相当直观

我的2美分,将在几分钟内发布给您如何调试 if 在第 169 行。

These td's, on line 178 and 194 can be greatly simplified.

   <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 />
                
       </td>';

Use this instead:

<td class="sub" width="100">';
    if ($file_employee != $emp_id)
    { 
        echo $file_employee;
    }
        echo'
        <br />
         
</td>';

Notice how using the ! operator simplifies the statement by more than half. Also, in my opinion you don't need a comment to say you are displaying $file_employee, it clutters your code needlessly since it is very obvious from the echo $file_employee that you are displaying it. Clean code with good indicative variable names should be easy to read, without needing many comments.

If you need a comment to reflect on a variable displayed, better rename the variable so it is clear just by looking at it. I also removed unused commented code, the result went from hard to understand at a quick glance to fairly intuitive at a glance

My 2 cents, will post you in a few minutes on how to debug that if on line 169.

心意如水 2024-11-21 23:56:40

好的,抱歉有多个答案,但在答案框中格式化更容易。

这一行,169:

if($_SESSION[$fgmembersite->GetLoginSessionVar()] != 'sa' 
&& ($file_confir == 'Approved' || $file_confir == 'NotApproved'))

您的查询返回所有结果,但这个 if 是根据这些条件显示结果集。

  1. 删除 if 中的条件,只保留第一个条件,如下所示:

    if($_SESSION[$fgmembersite->GetLoginSessionVar()] != 'sa')
    
  2. 使用第一个 td(空的)来回显 $file_confir 的结果

    回声'
    '。 $file_confir 。 '

    这将表明这些条件是否存在问题。

  3. 如果您仍然没有获得完整的预期结果集,您就会知道问题出在子句的第一个条件中:

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

我的猜测是问题可能是未设置的值$file_confir 或与其中的 2 不匹配的值。只有调试和耐心才能证明一切。

祝你好运的朋友。

Ok, sorry for multiple answers but formatting is easier in answer box.

This line, 169:

if($_SESSION[$fgmembersite->GetLoginSessionVar()] != 'sa' 
&& ($file_confir == 'Approved' || $file_confir == 'NotApproved'))

Your query returns all the results, but this if is what shows the resultset depending on these conditions.

  1. Remove the conditions in the if to have only the first one left in, as so:

    if($_SESSION[$fgmembersite->GetLoginSessionVar()] != 'sa')
    
  2. Use your first td ( the empty one) to echo the results of $file_confir

    echo '
    ' . $file_confir . '

    This will indicate if there is a problem with those conditions.

  3. If you still don't have your full expected resultset, you will know the problem is in the first condition of your clause:

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

My guess is the problem is problably unset values for $file_confir or a value that does not match the 2 you have in there. Only debugging and patience will tell.

Good-luck friend.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文