简体   繁体   中英

How do I exclude a Column from a mysql query in php?

I have a simple query (in a mySQL view) that php is using to create a table:

select `swtickets`.`ownerstaffid` AS `ID`,
`swtickets`.`ownerstaffname` AS `Owner`,
sum(if((`swtickets`.`ticketstatusid` = 2),1,0)) AS `In Progress`,
sum(if((`swtickets`.`ticketstatusid` = 4),1,0)) AS `Pending Customer`,
sum(if((`swtickets`.`ticketstatusid` = 5),1,0)) AS `Customer Replied`,
sum(if((`swtickets`.`ticketstatusid` = 9),1,0)) AS `Suggested Resolution`,
sum(if((`swtickets`.`priorityid` in (3,6) and `swtickets`.`ticketstatusid` in     (2,4,5,9)),1,0)) AS `High/Critical`,
sum(if((`swtickets`.`ticketstatusid` in (2,4,5,9)),1,0)) AS `Total Workable` 
from `swtickets` where ((`swtickets`.`departmentid` = 14) 
and ownerstaffid in (select staffid from swstaff where staffgroupid=4 and isenabled =  1)
and (`swtickets`.`ownerstaffname` <> '')) group by `swtickets`.`ownerstaffname`

I am calling the data in a while loop, but I can't seem to get rid of the 'ID' column, which I need to call as it serves as the target of the hyperlink for the Owner column. The ideal headers would be:

Owner | In Progress | Pending Customer | Customer Replied | Suggested Resolution | Total Workable

The php:

 $ticketloadquery = mysql_query("SELECT * from open_tickets;")
or die(mysql_error()); 

$ticketloadfield_num = mysql_num_fields($ticketloadquery);

echo "<div><h1>Work Load</h1>";
if(mysql_num_rows($ticketloadquery)==0) {
echo "<i>There are no currently unassigned tickets!</i>";
}
else{
echo "<table border='1'><tr>";
for($i=0; $i<$ticketloadfield_num; $i++)
{
$ticketloadfield = mysql_fetch_field($ticketloadquery);
echo "<td>{$ticketloadfield->name}</td>";
}
echo "</tr>\n";

while($ticketloadinfo = mysql_fetch_array( $ticketloadquery )) 
{ 

echo "<tr>"; 
echo "<td><a href='https://support.mysite.com/staff/dashboard.php?   id=".$ticketloadinfo['ID']."', target='_blank'>".$ticketloadinfo['Owner']."</a></td> "; 
echo "<td>".$ticketloadinfo['Owner'] . "</td> "; 
echo "<td>".$ticketloadinfo['In Progress'] . "</td> "; 
echo "<td>".$ticketloadinfo['Pending Customer'] . " </td>"; 
echo "<td>".$ticketloadinfo['Customer Replied'] . " </td>";
echo "<td>".$ticketloadinfo['Suggested Resolution'] . " </td>"; 

echo "<td>".$ticketloadinfo['Total Workable'] . " </td></tr>"; 
} 
echo "</div>";
echo "</table>"; 
}

Any suggestions?

Remove either

echo "<td><a href='https://support.mysite.com/staff/dashboard.php?   id=".$ticketloadinfo['ID']."', target='_blank'>".$ticketloadinfo['Owner']."</a></td> "; 

OR

echo "<td>".$ticketloadinfo['Owner'] . "</td> "; 

摆脱只有所有者的单元格,因为它与先前的单元格相同,只有超链接。

Even if you manage to make an exception for the ID column now, this approach is going to lead to problems in the future as you are automatically generating your columns from the query for the headers and then you are manually adding columns for the information you want to display.

There are two options:

  1. You generate all information automatically so that the header and content are always in sync. This is not recommended as you don't have any flexibility where it comes to how you want to display your information
  2. Add the header row manually as well. This way you can display whatever you want and you can use a simple block of html to achieve that.

As a side-note I would also recommend using th elements instead of td elements for the header row.

So you would replace:

for($i=0; $i<$ticketloadfield_num; $i++)
{
$ticketloadfield = mysql_fetch_field($ticketloadquery);
echo "<td>{$ticketloadfield->name}</td>";
}

with:

?>
<th>Owner</th>
<th>In Progress</th>
<th>Pending Customer</th>
<th>Customer Replied</th>
<th>Suggested Resolution</th>
<th>Total Workable</th>
<?php

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM