草庐IT

php - 在 php 中放置一些条件后,某些项目不会回显

coder 2024-04-22 原文

来自此链接 Echo problem when a different user logs in我之前发布的,我设法解决或解决了我的问题。但不知何故,发生了一个小错误。虽然我的管理页面工作正常,但我的 super 管理员和其他帐户开始输出错误(尽管它们并不是真正的错误)。员工id和员工姓名在 super 管理员页面和其他帐户中没有回显,但回显了标题(文件上传)、文件日期和状态。

//what i meant to say was, this is what the echo suppose to look like:
*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



//instead it echoed like this
*EmployeeID*     *EmployeeName*     *Title*     *FileDate*     *Status*           

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

//this is the actual output that appears on my localhost

this is the set of codes that i think might have caused the problem,i will put a remark one which if statement the problem i think causes error

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


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

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

                                echo '<tr>
                                    <td>
                                        &nbsp; 
                                    </td>
                                    </tr>
                                    <tr class="subone">
                                    <td class="sub" width="100">
                                        '.$emp_id.'
                                        <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$emp_name?></a>
                                        <br />
                                        &nbsp;
                                    </td><?php
                                    }
                                    else
                                        {
                                            echo '<td class="sub" width="182">
                                            '.$emp_name.' 
                                            <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>';
                                        }
                                    }
                                    /
                                    }
//I THINK THE PROBLEM STARTS HERE
                                    else 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">
                                        '.$emp_id.'
                                        <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$emp_name?></a>
                                        <br />
                                        &nbsp;
                                    </td><?php
                                    }
                                    else
                                        {
                                            echo '<td class="sub" width="182">
                                            '.$emp_name.' 
                                            <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>';
                                        }
                                    }
                                    }


                                }?>

我希望有人能帮我弄清楚是什么导致了这个输出。 :( 已经花了一个多小时弄明白了。感谢那些会回复的人。

米莎陈

最佳答案

在这两行中,如果员工 ID 和姓名与从数据库中检索到的 ID 和姓名相匹配,您实际上是在删除它们:

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

我怀疑你是否想改为这样做:

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

关于php - 在 php 中放置一些条件后,某些项目不会回显,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6249059/

有关php - 在 php 中放置一些条件后,某些项目不会回显的更多相关文章

  1. ruby - 如何在 buildr 项目中使用 Ruby 代码? - 2

    如何在buildr项目中使用Ruby?我在很多不同的项目中使用过Ruby、JRuby、Java和Clojure。我目前正在使用我的标准Ruby开发一个模拟应用程序,我想尝试使用Clojure后端(我确实喜欢功能代码)以及JRubygui和测试套件。我还可以看到在未来的不同项目中使用Scala作为后端。我想我要为我的项目尝试一下buildr(http://buildr.apache.org/),但我注意到buildr似乎没有设置为在项目中使用JRuby代码本身!这看起来有点傻,因为该工具旨在统一通用的JVM语言并且是在ruby中构建的。除了将输出的jar包含在一个独特的、仅限ruby​​

  2. ruby - Highline 询问方法不会使用同一行 - 2

    设置:狂欢ruby1.9.2高线(1.6.13)描述:我已经相当习惯在其他一些项目中使用highline,但已经有几个月没有使用它了。现在,在Ruby1.9.2上全新安装时,它似乎不允许在同一行回答提示。所以以前我会看到类似的东西:require"highline/import"ask"Whatisyourfavoritecolor?"并得到:Whatisyourfavoritecolor?|现在我看到类似的东西:Whatisyourfavoritecolor?|竖线(|)符号是我的终端光标。知道为什么会发生这种变化吗? 最佳答案

  3. ruby-on-rails - 项目升级后 Pow 不会更改 ruby​​ 版本 - 2

    我在我的Rails项目中使用Pow和powifygem。现在我尝试升级我的ruby​​版本(从1.9.3到2.0.0,我使用RVM)当我切换ruby​​版本、安装所有gem依赖项时,我通过运行railss并访问localhost:3000确保该应用程序正常运行以前,我通过使用pow访问http://my_app.dev来浏览我的应用程序。升级后,由于错误Bundler::RubyVersionMismatch:YourRubyversionis1.9.3,butyourGemfilespecified2.0.0,此url不起作用我尝试过的:重新创建pow应用程序重启pow服务器更新战俘

  4. ruby-on-rails - 新 Rails 项目 : 'bundle install' can't install rails in gemfile - 2

    我已经像这样安装了一个新的Rails项目:$railsnewsite它执行并到达:bundleinstall但是当它似乎尝试安装依赖项时我得到了这个错误Gem::Ext::BuildError:ERROR:Failedtobuildgemnativeextension./System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/bin/rubyextconf.rbcheckingforlibkern/OSAtomic.h...yescreatingMakefilemake"DESTDIR="cleanmake"DESTDIR="

  5. ruby - 如何根据特征实现 FactoryGirl 的条件行为 - 2

    我有一个用户工厂。我希望默认情况下确认用户。但是鉴于unconfirmed特征,我不希望它们被确认。虽然我有一个基于实现细节而不是抽象的工作实现,但我想知道如何正确地做到这一点。factory:userdoafter(:create)do|user,evaluator|#unwantedimplementationdetailshereunlessFactoryGirl.factories[:user].defined_traits.map(&:name).include?(:unconfirmed)user.confirm!endendtrait:unconfirmeddoenden

  6. ruby-on-rails - 在 Rails 和 ActiveRecord 中查询时忽略某些字段 - 2

    我知道我可以指定某些字段来使用pluck查询数据库。ids=Item.where('due_at但是我想知道,是否有一种方法可以指定我想避免从数据库查询的某些字段。某种反拔?posts=Post.where(published:true).do_not_lookup(:enormous_field) 最佳答案 Model#attribute_names应该返回列/属性数组。您可以排除其中一些并传递给pluck或select方法。像这样:posts=Post.where(published:true).select(Post.attr

  7. ruby - 在 Ruby 中有条件地定义函数 - 2

    我有一些代码在几个不同的位置之一运行:作为具有调试输出的命令行工具,作为不接受任何输出的更大程序的一部分,以及在Rails环境中。有时我需要根据代码的位置对代码进行细微的更改,我意识到以下样式似乎可行:print"Testingnestedfunctionsdefined\n"CLI=trueifCLIdeftest_printprint"CommandLineVersion\n"endelsedeftest_printprint"ReleaseVersion\n"endendtest_print()这导致:TestingnestedfunctionsdefinedCommandLin

  8. ruby - 定义方法参数的条件 - 2

    我有一个只接受一个参数的方法:defmy_method(number)end如果使用number调用方法,我该如何引发错误??通常,我如何定义方法参数的条件?比如我想在调用的时候报错:my_method(1) 最佳答案 您可以添加guard在函数的开头,如果参数无效则引发异常。例如:defmy_method(number)failArgumentError,"Inputshouldbegreaterthanorequalto2"ifnumbereputse.messageend#=>Inputshouldbegreaterthano

  9. Ruby 从大范围中获取第 n 个项目 - 2

    假设我有这个范围:("aaaaa".."zzzzz")如何在不事先/每次生成整个项目的情况下从范围中获取第N个项目? 最佳答案 一种快速简便的方法:("aaaaa".."zzzzz").first(42).last#==>"aaabp"如果出于某种原因你不得不一遍又一遍地这样做,或者如果你需要避免为前N个元素构建中间数组,你可以这样写:moduleEnumerabledefskip(n)returnto_enum:skip,nunlessblock_given?each_with_indexdo|item,index|yieldit

  10. ruby-on-rails - 如何生成传递一些自定义参数的 `link_to` URL? - 2

    我正在使用RubyonRails3.0.9,我想生成一个传递一些自定义参数的link_toURL。也就是说,有一个articles_path(www.my_web_site_name.com/articles)我想生成如下内容:link_to'Samplelinktitle',...#HereIshouldimplementthecode#=>'http://www.my_web_site_name.com/articles?param1=value1¶m2=value2&...我如何编写link_to语句“alàRubyonRailsWay”以实现该目的?如果我想通过传递一些

随机推荐