some item won't echo after putting some condition in php
from this link Echo problem when a different user logs in that i posted earlier, i managed to do or fix my problem. but somehow, there is a small error that have occurred. although my admin page is working properly, my super admin and other accounts began to output errors (although they are not really error). the employee id and employee name did not echo in the super admin page and other accounts, although the title(file uploaded),file date and status 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 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>
</td>
</tr>
<tr class="subone">
<td class="sub" width="100">
'.$emp_id.'
<br />
</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 />
</td><?php
}
else
{
echo '<td class="sub" width="182">
'.$emp_name.'
<br />
</td>';
}
echo'<td class="sub" width="218">
<a href="'.$file_accs.$file_name.'" target="_blank" style="text-decoration: underline;">'.$file_desc.'</a>
<br />
</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 />
</td>
<td class="sub" width="100">
'.$file_confir.'
<br />
</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 />
</td>';
}
}
/
}
//I THINK THE PROBLEM STARTS HERE
else if($_SESSION[$fgmembersite->GetLoginSessionVar()] != 'sa' && ($file_confir == 'Approved' || $file_confir == 'NotApproved'))
{
echo '<tr>
<td>
</td>
</tr>
<tr class="subone">
<td class="sub" width="100">
'.$emp_id.'
<br />
</td>';
if($_SESSION[$fgmembersite->GetLoginSessionVar()] == 'sa')
开发者_JAVA百科 {
?><td class="sub" width="100">
<a href="" onclick = javascript:newPopup('addfile.php?emp=<?php echo $file_employee ?>');><?php echo$emp_name?></a>
<br />
</td><?php
}
else
{
echo '<td class="sub" width="182">
'.$emp_name.'
<br />
</td>';
}
echo'<td class="sub" width="218">
<a href="'.$file_accs.$file_name.'" target="_blank" style="text-decoration: underline;">'.$file_desc.'</a>
<br />
</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 />
</td>
<td class="sub" width="100">
'.$file_confir.'
<br />
</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 />
</td>';
}
}
}
}?>
i hope someone could help me figure out what caused this output. :( already spent more that an hour figuring it out. thanks for those that will reply.
MisaChan
In these 2 lines, you're effectively deleting the employee ID and name if they match those retrieved 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 if you wanted to do this instead:
$emp_id = ($emp_id==$row['employee_id']) ? $emp_id : $row['employee_id'];
$emp_name = ($emp_name==$row['employee_name']) ? $emp_name : $row['employee_name'];
Now I understand what you wanted. Here is the guide line of what should have been done instead of overwriting the ID and name on the fly.
# these are used to save the previously processed entry's 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's ID and name
echo '<td>' . $file_employee . '</td><td>' . $file_ename . '</td>';
}
else
{
# display the employee's ID and name
echo '<td> </td><td> </td>';
}
# display other info (i.e. 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's ID and name
$last_emp_id = $file_employee;
$last_emp_name = $file_ename;
}
Let me know if you need further help.
why the line
if($_SESSION[$fgmembersite->GetLoginSessionVar()] == 'sa')
is inside block
else if($_SESSION[$fgmembersite->GetLoginSessionVar()] != 'sa'
It never executes once the else if
fails.
精彩评论