简体   繁体   English

如何从php的mysql查询中排除列?

[英]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: 我有一个简单的查询(在mySQL视图中),php使用它来创建表:

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. 我在while循环中调用数据,但似乎无法摆脱“ ID”列,我需要调用它,因为它用作“所有者”列的超链接的目标。 The ideal headers would be: 理想的标头是:

Owner | 业主| In Progress | 进行中| Pending Customer | 待定客户| Customer Replied | 客户回复| Suggested Resolution | 建议的分辨率| Total Workable 总可行

The php: 的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. 即使您现在设法对ID列进行例外处理,这种方法也会在将来导致问题,因为您是根据标题的查询自动生成列,然后手动添加所需信息的列显示。

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. 这样,您可以显示所需的任何内容,并且可以使用简单的html块来实现。

As a side-note I would also recommend using th elements instead of td elements for the header row. 作为一个旁注,我还建议在标题行中使用th元素而不是td元素。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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