簡體   English   中英

在表格中集成href鏈接

[英]Integrate href link in table

我試圖在我的php表中放入一些URL鏈接。 我已經在PHP頁面上運行了該表。 我需要將“ Rute_navn”列激活為網址鏈接。 我在網上找到了一個代碼字符串,但是我不知道將其放在PHP表代碼中的哪個位置。

有人有什么建議嗎? 我試圖將單個代碼行粘貼到多個位置,但是每次表更改外觀時都會出現一些奇怪的情況。

我的單行代碼:

<?php echo"<a href='result.php?id=$Rute_navn'>$Rute_navn</a>";?> 

這是我的主要PHP表代碼:

<?php
    //$db_host = 'localhost';
    //$db_user = 'user';
    //$db_pwd = 'password';
    //$database = 'database';
    //$table = 'Avisruter';

    if (!mysql_connect('localhost', 'user', 'password'))
    die("Can't connect to database");

    if (!mysql_select_db('database'))
    die("Can't select database");

    // sending query
    $result = mysql_query ("SELECT Rute_nr, Rute_navn FROM Avisruter WHERE Bruger=''");
    if (!$result) {
        die("Query to show fields from table failed");
    }

    $fields_num = mysql_num_fields($result);

    echo "<h2>Ledige avisruter</h2>";
    echo "<table border='5' width=305> <tr>";

    // printing table headers
    for($i=0; $i<$fields_num; $i++) {
        $field = mysql_fetch_field($result);
        echo "<td>{$field->name}</td>";
    }
    echo "</tr>\n";

    while($row = mysql_fetch_row($result)) {
        echo "<tr>";

        foreach($row as $cell)
            echo "<td>$cell</td>";

        echo "</tr>\n";
    }
    mysql_free_result($result);
?>

更改

foreach($row as $cell)
   echo "<td>$cell</td>";

foreach($row as $column => $value){
    if ($column == 'Rute_navn') {
        echo "<td><a href='result.php?id=$value'>$value</a></td>";
    } else {
        echo "<td>$value</td>";
    }
}
while($row = mysql_fetch_row($result))
    {

            echo "<tr>";

           foreach($row as $cell){
             if($cell == "Rute_navn"){
             echo "<td><a href='result.php?id=$Rute_navn'>$Rute_navn</a></td>";
                                     }
              else
        echo "<td>$cell</td>";
}

        echo "</tr>\n";
    }

暫無
暫無

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

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