开发者

don't echo correctly and error in loops [duplicate]

This question already has an answer here: Closed 11 years ago.

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 differen开发者_开发问答t 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 :(


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


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

Use this instead:

<td class="sub" width="100">';
    if ($file_employee != $emp_id)
    { 
        echo $file_employee;
    }
        echo'
        <br />
        &nbsp;
</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.


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.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜