gpt4 book ai didi

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

转载 作者:可可西里 更新时间:2023-10-31 23:50:18 25 4
gpt4 key购买 nike

来自此链接 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com