dreamfly0514 2014-05-27 20:57
浏览 25
已采纳

php - 添加指向我的SQL查询表的链接

I currently have a functioning table displaying on my website using the following query/table display. I need to modify how the table is displayed so I can make the final column a link based on their CompanyID I call in the query.

Query (sanitized for security):

$tableResults = dbQuery('SELECT CompanyName, ContractStatus, LEFT(ContractDate, 10), CCNumber, LevelName, cinfo.CompanyID 
FROM <databases> WHERE <things>
order by CompanyName');

while($tableRow = mysql_fetch_assoc($tableResults))
{
    $tableData[] = $tableRow;
}

$tableColNames = array_keys(reset($tableData));

And the table (ignore the formatting, the data structure is my concern):

<table width="100%" border="0" cellspacing="1" cellpadding="5" class="tablesorter" id="contcomm_table">
    <thead>
        <tr>
            <th class="header"><strong>Company Name</strong></th>
            <th class="header"><strong>Contract Status</strong></th>
            <th class="header"><strong>Contract Date</strong></th> 
            <th class="header"><strong>Writing Number</strong></th>
            <th class="header"><strong>View Comm Schedule</strong></th>
        </tr>
    </thead>
<tbody>
<?
    foreach($tableData as $row)
    {
        echo "<tr>";
        foreach($tableColNames as $colName)
        {
            echo "<td>" . $row[$colName] . "</td>";
        }
        echo "</tr>";
    }
?>
</tbody>
</table>

The link in question would be '/_Document.pdf'. I think I'm having a case of the Mondays, because I just can't grasp this right now.

EDIT: The answers so far have gotten me closer, and now I just need to get over the last hump. I have everything displaying right, and the URL will show up... but now I need to concatenate the URL with the Company ID in the URL.

So, the relevant area I'm working on now, along with my best efforts at it:

if ($colName=='LevelName') {
    echo "<td><a href='http://my.url.here/".$CompanyID."_Document.pdf' target='_blank'>" . $row[$colName] . "</a></td>";
}
else {
    echo "<td>" . $row[$colName] . "</td>";
}
  • 写回答

4条回答 默认 最新

  • duanpan7011 2014-05-27 21:08
    关注

    Should something like this:

    <table width="100%" border="0" cellspacing="1" cellpadding="5" class="tablesorter" id="contcomm_table">
        <thead>
            <tr>
                <th class="header"><strong>Company Name</strong></th>
                <th class="header"><strong>Contract Status</strong></th>
                <th class="header"><strong>Contract Date</strong></th> 
                <th class="header"><strong>Writing Number</strong></th>
                <th class="header"><strong>View Comm Schedule</strong></th>
            </tr>
        </thead>
    <tbody>
    <?
        foreach($tableData as $row)
        {
            echo "<tr>";
            foreach($tableColNames as $colName)
            {
                if ($colName=='name_of_you_link)' echo "<td><a href='/_Document.pdf'>" . $row[$colName] . "</td>";
                    echo "<td>" . $row[$colName] . "</td>";
            }
            echo "</tr>";
        }
    ?>
    </tbody>
    </table>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 正弦信号发生器串并联电路电阻无法保持同步怎么办
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
  • ¥15 个人网站被恶意大量访问,怎么办
  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 Centos / PETGEM
  • ¥15 划分vlan后不通了
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)