Reputation: 279
I dont know how to repost questions so im just gonna link my old post here some item won't echo after putting some condition in php
although some problems were solved there thanks to @Shinkou, there are still errors found in my program.I tried to figure out what caused this problem but i found no luck in solving them.
now let me tell you what my program does.i have 2 admins with different functions. the admin uploads file,and registers a new company and employee detail.he is also responsible for deleting the not approved or pending files.(NO PROBLEMS HERE ^_^) the 2nd one is superadmin. its purpose is to view uploaded files and approve or reject the file uploaded. (AS YOU SEE, ITS ALL ABOUT THE FILES UPLOADED BY THE ADMIN) the other user are the company account.this account is created when the admin registers a new company.Its purpose is just for viewing which file have been approved or rejected by the superadmin.
my problem is all in the superadmin and other user.but lets talk about the superadmin more.my superadmin contains 3 menubars(i used link images here-working)->HOME(to view all accepted/rejected files),NEW UPLOAD(to view and accept/reject all pending files)and LOGOUT.the NEWUPLOAD and LOGOUT is working,but i am having problems with home and it affects the other user accounts.Lastly,code format is something like this.let me show you:
*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 //if you could notice employee riorei,it contains 2 files,the employeename and id will be displayed only once. this one is also already sorted as you could notice i wish.
let me list up all the problems i encountered and things i discovered as i trace the problem:
as far as i noticed,this is the only error i found. so let me show you the codes i used :)
<?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.
$count = 0;
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'];
$count = $count + 1;
echo $count;
if($_SESSION[$fgmembersite->GetLoginSessionVar()] == 'sa')
{
echo '<tr>
<td>
</td>
</tr>
<tr class="subone">
<td class="sub" width="100">
';
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 />
</td>';
if($_SESSION[$fgmembersite->GetLoginSessionVar()] == 'sa')
{
?><td class="sub" width="100">
<a href="" onclick = javascript:newPopup('addfile.php?emp=<?php echo $file_employee ?>');>
<?php if ($file_ename == $emp_name)
{
# do not display the employee's ID and name
}
else
{
# display the employee's ID and name
echo''.$file_ename.'';
}?></a>
<br />
</td><?php
}
else
{
echo '<td class="sub" width="182">
';
if ($file_ename == $emp_name)
{
# do not display the employee's ID and name
}
else
{
# display the employee's ID and name
echo''.$file_ename.'';
}
echo'
<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>';
}
}
}
else
//THIS IS THE CODES OF MY SUPER ADMIN AND OTHER ACCOUNTS
if($_SESSION[$fgmembersite->GetLoginSessionVar()] != 'sa' && ($file_confir == 'Approved' || $file_confir == 'NotApproved'))
{
echo '<tr>
<td>
</td>
</tr>
<tr class="subone">
<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 />
</td>';
echo '<td class="sub" width="182">';
if ($file_ename == $emp_name)
{
# do not display the employee's ID and name
}
else
{
# display the employee's ID and name
echo''.$file_ename.'';
}
echo'
<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>';
}
$emp_id = $file_employee;
$emp_name = $file_ename;
}?>
<tr>
SORRY if its too long,its just that some requires or ask the complete codes i used,although this is just part.i hope someone could help me here. :(
Upvotes: 2
Views: 1614
Reputation: 279
I have finally discovered what went wrong with my problem. Although my codes became longer that ever.
So here's what I did, I added new query for my conditions "pending", "notapproved" and "approved" its the same query actually, i just added AND e
.confirmation
LIKE 'Pending' in the newupload page and AND e
.confirmation
LIKE 'Accepted' OR e
.confirmation
LIKE 'NotAccepted' in the home page. (note that i put this together with the query and created $sql2,$query2,$total2 and $result2 and since I have 1 code for page number, I already fixed that as well)
At the same time, instead of having WHILE first then If Statement, I have reversed it. And have done 2 whiles.
You could check in my codes and apply this :)
Thanks to @stefgosselin for not putting me down and the one who "ONLY" helped me in someways. I just tried it now, all i need to do now is to correct my order by. Thanks. Hope this could help others with the same problem.
Upvotes: 1