【问题标题】:How to create a url for row in database ("<td>" .$row["website"] ."</td>";)如何为数据库中的行创建 url ("<td>" .$row["website"] ."</td>";)
【发布时间】:2021-10-09 03:02:12
【问题描述】:

我在 phpMyAdmin 中创建了一个数据库,我有 10 行数据,每行都有一个列来显示其网站地址。我想让网站地址可点击。

我使用下面的数组方法来显示我的网址链接,但它不起作用

    $website = array(
    array("Google","https://code.tutsplus.com"),
    array("Bing","https://weatherstack.com"),
    array("W3","https://www.w3schools.com")
   
    );

    foreach ($website as $urlitem){ 
    echo "<a href='".$urlitem[1]."'></a>";
    }

    

    // this gets an associative array (ie the keys can be used as well as the indicies)
    while ($row = $stmt->fetch(PDO::FETCH_ASSOC)){


   // The below code displays my table


        echo "<tr>";
         
        echo "<td>" . $row['id'] . "</td>";
        echo "<td>" . $row['type'] . "</td>";
        echo "<td>" . $row['name'] . "</td>";
        echo "<td>" . $row['street'] . "</td>";
        echo "<td>" . $row['city'] . "</td>";
        echo "<td>" . $row['region'] . "</td>";
        echo "<td>" . $row['code'] . "</td>";
        echo "<td>" . $row['phone'] . "</td>";
          echo "<td><a href='".$urlitem[0]."'>" .$row["website"] ."</td>";
       

        echo "</tr>";            
    }

} 

【问题讨论】:

    标签: php sql arrays url


    【解决方案1】:

    foreach 循环中,问题是您没有打印出任何要为锚标记显示的内容。表示您的锚标签存在,但它没有任何内容要显示在 html 上;

    <a href="">YOUR CONTENT MISSING PART</a>
    

    之后,在您的 while 循环中,您将使用不存在的变量 $urlitem。您要么需要在foreach 之外声明它,要么需要使用$website 变量来获取url

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-06-24
      • 1970-01-01
      • 2015-02-11
      • 2023-03-21
      • 1970-01-01
      • 1970-01-01
      • 2020-01-02
      相关资源
      最近更新 更多