PHP在查询行中使用foreach动态表头

时间:2016-06-15 14:42:38

标签: php html mysql

你有一个mysql表“position”:

posID posName posQty 12 Agent 20 13 Supervisor 3 14 Manager 1 16 Teamlead 4

我正在使用mysql表“departments”的连接,我需要的是在echoed表的列标题中动态加载posName,然后在每个相应的列/行交集中显示posQty计数:

Dept Agent Supervisor Manager Teamlead sales 4 1 1 2 support 6 1 0 1 hr 10 1 0 1

我有什么:

mysql_select_db("callcenter");
$query = "SELECT * FROM cscc_stakeholders JOIN employee ON employee.stakeholder_code = cscc_stakeholders.stakeholder_code
LEFT JOIN cscc_segments ON cscc_segments.segment_code = employee.segment_code GROUP BY cscc_stakeholders.stakeholder_code";
$sql = @mysql_query($query);
echo "<div><font size=\"3\"><table class=\"table table-bordered table-hover\" id=\"ticket_search_table\"><caption>By Segment</caption>";
$queryhead = "SELECT posName FROM cscc_headcount GROUP BY posName ORDER BY hcountId ASC";
$queryemployee = "SELECT posName FROM cscc_headcount GROUP BY posName";
$sqlhead = @mysql_query($queryhead);
    echo "<thead style=\"background-color:#424242; color: #E6E6E6\"><br/>";
    echo("<tr><th></th>");
    while($rowhead = @mysql_fetch_array($sqlhead)){
    $positions = array();
    foreach ($rowhead as $row_value){}
     $positions[] = $row_value; 
print_r($positions);
    echo("<td>".$row_value."</td>");}

0 个答案:

没有答案