簡體   English   中英

使用來自SQL查詢的數據,但不顯示表中的列

[英]Use data from an SQL query, but don't display column in table

編輯:如果我使用$ colName而不是$ colname,則不會有任何問題。 愚蠢的簡單解決方法。

我有一個查詢從多個表中提取6列。 最后一列必須在我生成的動態URL中使用,但是我不希望該列顯示在我的表上。 如何隱藏它/使其不顯示? 有沒有一種方法可以調用數據,但不能在表中使用它?

查詢前:

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

表(您可以看到我的標題行可以隱藏,但內容不會隱藏):

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

您有一個錯字: $colname應該是$colName

if ($colname=='CID') {

愚蠢的簡單解決方案:使用$ colName代替$ colname。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM