使用php从数据库中获取超链接数据

时间:2015-10-26 08:24:39

标签: php html mysql

我是php和html的新手。我需要从mySQL中检索数据,我帮忙完成了。现在,我需要数据是超链接,点击时,它将被重定向到一个新页面,显示我有关数据的详细信息

This is the data I retrieve from the database. I need it to be hyperlink and each data to be redirected to their respective php website

    <!DOCTYPE HTML>

<html>

<head>
  <title>Static IP Address Management Portal</title>
  <meta name="description" content="website description" />
  <meta name="keywords" content="website keywords, website keywords" />
  <meta http-equiv="content-type" content="text/html; charset=UTF-8" />
  <link rel="stylesheet" type="text/css" href="css/style.css" />
  <link rel="stylesheet" href="css/skeleton.css">
  <link rel="stylesheet" href="css/layout.css">
  <!-- modernizr enables HTML5 elements and feature detects -->
  <script type="text/javascript" src="js/modernizr-1.5.min.js"></script>

</head>

<body>
    <div class="container">
        <div class="sixteen columns">
            <div id="logo">
                <div id="logo_text">
                    <!-- class="logo_colour", allows you to change the colour of the text -->
                    <img class="logo" src="images/nyp.png" alt="NYP"/> 
                    <font size ="3.5"><h1>Static IP Address Management Portal    </h1></font>
                    <h2 class="text"><font color="red">View Pool</font> </h2>
                </div>
            </div>
        </div>
    </div><!-- End container -->

    <div class="container">
        <font size="4" >
            <nav>
                <ul class="sf-menu" id="nav">
                    <li><a href="Admin.php">Home</a></li>
                    <li><a href="CreateIPPool.php">Create Pool</a></li>
                    <li class="selected"><a href="ViewIPPool.php">View Pool</a></li>
                    <li><a href="Request.php">Request</a></li>
                    <li><a href="Logout.php">Logout</a></li>
                </ul>
            </nav>
        </font>
    </div><!-- End container -->

    <div class="container">
        <font size="4" >
            <div class="sixteen columns">
                <div id="site_content">
                    <div id="content">
                        <div class="center">
                            <?php
                                $servername = "localhost";
                                $username = "root";
                                $password = "123456";
                                $dbname = "ipPool";

                                // Create connection
                                $conn = new mysqli($servername, $username, $password, $dbname);
                                // Check connection
                                if ($conn->connect_error) {
                                     die("Connection failed: " . $conn->connect_error);
                                } 

                                $sql = "SELECT PoolName FROM PoolName";
                                $result = $conn->query($sql);

                                if ($result->num_rows > 0) {
                                     echo "<table><tr><th>PoolName</th></tr>";
                                     // output data of each row
                                     while($row = $result->fetch_assoc()) {
                                         echo "<tr><td>" . $row["PoolName"]. "</td></tr>";
                                     }
                                     echo "</table>";
                                } else {
                                     echo "0 results";
                                }

                                $conn->close();
                            ?>  
                        </div>
                    </div>
                </div>
            </div>
        </font>
    </div><!-- End container -->

    <div class="container">
        <font size="4" >
            <footer>
                <p>Copyright &copy; 2015 Nanyang Polytechnic, School of Information Technology.  </p>
            </footer>
        </font>
    </div><!-- End container -->

  <p>&nbsp;</p>
  <!-- javascript at the bottom for fast page loading -->
  <script type="text/javascript" src="js/jquery.js"></script>
  <script type="text/javascript" src="js/jquery.easing-sooper.js"></script>
  <script type="text/javascript" src="js/jquery.sooperfish.js"></script>
  <script type="text/javascript">
    $(document).ready(function() {
      $('ul.sf-menu').sooperfish();
    });
  </script>
</body>
</html>

3 个答案:

答案 0 :(得分:1)

尝试更新

echo "<tr><td>" . $row["PoolName"]. "</td></tr>";

类似

echo "<tr><td><a href='your desired url Goes here'>" . $row["PoolName"]. "</a></td></tr>";

答案 1 :(得分:0)

因此 您必须存储网站以及数据库

假设您的数据库包含列名website

然后 查询 应为

$sql = "SELECT PoolName,website FROM PoolName";

所以while循环

echo "<tr><td><a href='".$row["website"]."'>". $row["PoolName"]. "</a></td></tr>";

答案 2 :(得分:-1)

试试这个,您需要更改超链接以导航到其他地方。

 echo "<tr><td><a href='google.com'>". $row["PoolName"]. "</a></td></tr>";