dtuct88226 2014-05-28 13:45
浏览 73
已采纳

使用SQL查询中的数据,但不显示表中的列

EDIT: If I use $colName instead of $colname, I'd have no issues. Stupid, simple fix.

I have a query pulling 6 columns from multiple tables. The final column is necessary to be used in a dynamic URL I'm generating, but I don't want that column to display on my table. How can I hide it/make it not show up? Is there a way to call the data, but not use it in my table?

Query ex:

SELECT a, b, c, d, e, exTable.f as CID
FROM table exTable
JOIN <other tables>
WHERE stuff happens

Table (you can see that my header row will hide fine, but the content won't):

<table>
<thead>
    <tr>
        <th class="header"><strong>A</strong></th>
        <th class="header"><strong>B</strong></th>
        <th class="header"><strong>C</strong></th> 
        <th class="header"><strong>D</strong></th>
        <th class="header"><strong>E</strong></th>
        <th class="header" style="display:none"><strong>F</strong></th> <!-- THIS WORKS -->
    </tr>
</thead>
<tbody>
    <?
        foreach($tableData as $row)
        {
            echo "<tr>";
            foreach($tableColNames as $colName)
                {
                    if ($colname=='CID') {
                    echo "<td style='display:none'>" . $row[$colName] . "</td>"; <!-- THIS DOES NOT -->
                    }
                    elseif ($colName=='e') {
                        echo "<td><a href='http://my.url.here/".$row[CID]."_Document.pdf' target='_blank'>" . $row[$colName] . " </a></td>";
                    }
                    else {
                    echo "<td>" . $row[$colName] . "</td>";
                    }
                }
            echo "</tr>";
        }
        ?>
    </tbody>
</table>
  • 写回答

2条回答 默认 最新

  • duanaigua4033 2014-05-28 13:48
    关注

    You have a typo: $colname should be $colName.

    if ($colname=='CID') {
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度