Some element will not echo after putting some condition in php

this link The echo problem, when another user logs in to the one I posted earlier, I managed or fixed my problem. but for some reason a small error occurred. although my admin page is working correctly, my super-administrator and other accounts started to display errors (although they are not really a mistake). the employee name and employee name were not displayed on the super admin page and other accounts, although the title (file uploaded), date and file status were echoed.

  // 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 a set of codes that, I think, could cause a problem, I will put a remark that, if the statement causes an error, I think it causes an error

<?php $search = '%'; $fgmembersite->DBLogin(); $limit = 5; if(isset($_GET['offset'])) { $offset = mysql_real_escape_string($_GET['offset']); } else { $offset = 0; } //for namelist az $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>'; } } } }?> 

Hope someone can help me figure out what caused this exit. :( already spent more than an hour figuring this out. Thanks to those who answer.

Misacan

+4
source share
3 answers

In these two lines, you actually delete the identifier and name of the employee, if they match those received from the database:

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

I doubt you wanted to do this:

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

Now I understand what you wanted. Below is the help line that should have been done instead of rewriting the identifier and name on the fly.

 # these are used to save the previously processed entry info $last_emp_id = ''; $last_emp_name = ''; 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']); $file_date_formatted = date ( 'M d, Y' , mktime ( 0 , 0 , 0 , substr($file_date, 5, 2) , substr($file_date, 8, 2) , substr($file_date, 0, 4) ) ); # begin a row echo '<tr>'; if ($file_employee == $last_emp_id) { # do not display the employee ID and name echo '<td>' . $file_employee . '</td><td>' . $file_ename . '</td>'; } else { # display the employee ID and name echo '<td>&nbsp;</td><td>&nbsp;</td>'; } # display other info (ie title, file date, and status) echo '<td>' . $file_accs . $file_name . '</td><td>' . $file_date_formatted . '</td><td>' . $file_confir . '</td'; # end the row echo "</tr>\n"; # update employee ID and name $last_emp_id = $file_employee; $last_emp_name = $file_ename; } 

Let me know if you need more help.

0
source

why line

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

is inside the block

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

It is never executed as soon as the else if fails.

0
source

All Articles