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

时间:2012-06-26 01:04:38

标签: php mysql

我有一个简单的查询(在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`

我在while循环中调用数据,但我似乎无法摆脱'ID'列,我需要调用它,因为它作为Owner列的超链接的目标。理想的标题是:

所有者|正在进行中|等待客户|客户回复|建议的决议|总可行

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>"; 
}

有什么建议吗?

3 个答案:

答案 0 :(得分:0)

删除

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> "; 

答案 1 :(得分:0)

删除只拥有所有者的单元格,因为它与前一个单元格相同,只是没有超链接。

答案 2 :(得分:0)

即使您现在设法为ID列设置例外,这种方法将来会导致问题,因为您会自动从标题查询生成列,然后手动生成为要显示的信息添加列。

有两种选择:

  1. 您会自动生成所有信息,以便标题和内容始终保持同步。建议不要这样做,因为您在如何显示信息方面没有任何灵活性
  2. 也手动添加标题行。这样你可以显示你想要的任何东西,你可以使用一个简单的html块来实现它。
  3. 作为附注,我还建议在标题行中使用th元素而不是td元素。

    所以你要替换:

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

    使用:

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