某些项目在php中添加一些条件后不会回显 [英] some item won't echo after putting some condition in php
问题描述
通过此链接不同用户登录时的回声问题,我之前发布的信息,我设法做的或修复了我的问题问题。但不知何故,发生了一个小错误。虽然我的管理页面正常工作,但我的超级管理员和其他帐户开始输出错误(尽管它们并非真正的错误)。尽管标题(文件上传),文件日期和状态有所回应,但员工ID和员工姓名未在超级管理员页面和其他帐户中回显。
//我的意思是说,这是echo假设的样子:
* EmployeeID * * EmployeeName * * Title * * FileDate * * Status *
20132248 Danica file8 Jan 08,2001已批准
20896647 Jan file7 2000年12月12日未批准
20864125 Keisha file2 2000年2月1日已批准
16521253 Riorei file10 2003年3月20日未批准
file3七月2002年12月14日批准
//而不是像这样回应
* EmployeeID * * EmployeeName * * Title * * FileDate * * Status *
file8 2001年1月8日批准
file7 2000年12月12日NotApproved
20864125 Keisha file2 2000年2月1日已批准
file10 2003年3月20日未批准
file3 2002年7月14日已核准
//这是在我的本地主机上出现的实际输出
这是我认为可能导致问题的一组代码,我会提出一个注释其中一个if语句是我认为会导致错误的问题
<?php
$ search ='%';
$ fgmembersite-> DBLogin();
$ limit = 5;
if(isset($ _ GET ['offset'])){
$ offset = mysql_real_escape_string($ _ GET ['offset']);
} else {
$ offset = 0;
}
//用于名称列表a-z
$ listname ='%';
if(isset($ _ GET ['namelist']))
{
$ listname = $ _GET ['namelist'];
搜索文件
if(isset($ _ POST ['searchfile']))
{
$ search = $ _POST [ 'searchfile'];
}
else if(isset($ _ GET ['searchfile']))
{
$ search = $ _GET ['searchfile']; ($ _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%'或`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()]。''和'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)或die(mysql_error());
$ result = mysql_query($ sql)或die(mysql_error());
$ total = mysql_num_rows($ result);
$ emp_id =; / /这将用于删除employee_id,如果它已经回显。
$ emp_name =; / /这将用于删除employee_name,如果它已经回显。
$ b $ if(!$ result || mysql_num_rows($ result)< = 0)
{
$ fgmembersite-> HandleError(No file found。 );
返回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'];
$ b $ if($ _ SESSION [$ fgmembersite-> GetLoginSessionVar()] =='sa')
{
echo'< tr>
< td>
& nbsp;
< / td>
< / tr>
< tr class =subone>
< td class =subwidth =100>
'。$ emp_id。'
< br />
& nbsp;
< / td>';
if($ _ SESSION [$ fgmembersite-> GetLoginSessionVar()] =='sa')
{
?>< td class =subwidth = 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 =subwidth =182>
'。$ emp_name。'
< br />
& nbsp;
< / td>';
}
echo'< td class =subwidth =218>
< a href ='。$ file_accs。$ file_name。'target =_ blankstyle =text-decoration:underline;>'。$ file_desc。'< / a>
< br />
& nbsp;
< / td>
< td class =subwidth =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 =subwidth =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 =subwidth =100>
< a href =index.php?id ='。$ file_id。'>删除< / a>
< br />
& nbsp;
< / td>';
$ b //我认为问题从这里开始
else if($ _ SESSION [$ fgmembersite-> GetLoginSessionVar() ]!='sa'&&($ file_confir =='Approved'|| $ file_confir =='NotApproved'))
{
echo'< tr>
< td>
& nbsp;
< / td>
< / tr>
< tr class =subone>
< td class =subwidth =100>
'。$ emp_id。'
< br />
& nbsp;
< / td>';
if($ _ SESSION [$ fgmembersite-> GetLoginSessionVar()] =='sa')
{
?>< td class =subwidth = 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 =subwidth =182>
'。$ emp_name。'
< br />
& nbsp;
< / td>';
}
echo'< td class =subwidth =218>
< a href ='。$ file_accs。$ file_name。'target =_ blankstyle =text-decoration:underline;>'。$ file_desc。'< / a>
< br />
& nbsp;
< / td>
< td class =subwidth =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 =subwidth =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 =subwidth =100>
< a href =index.php?id ='。$ file_id。'>删除< / a>
< br />
& nbsp;
< / td>';
}
}
}
}?>
我希望有人能帮我弄清楚是什么导致了这个输出。 :(已经花了一个多小时才算出来,谢谢那些会回复的人。)
MisaChan
if($ _ SESSION [ ] =='sa')
在块内
else if($ _ SESSION [$ fgmembersite-> GetLoginSessionVar()]!='sa'
如果 else 失败,那么它永远不会执行。
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')
{
?><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
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.
这篇关于某些项目在php中添加一些条件后不会回显的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!