0
基本上,我想使每個元組指向不同的URL,以便我可以查看所單擊的部門的學期,並且我正在查看此表。想要使每個元組指向不同的鏈接,我該怎麼做?
我嘗試在此代碼中的echo之前傳遞一個href標記,但是當我按下表中的任何元組時,這是帶我到相同的鏈接。
<!Doctype html>
<table border="1" id="table">
<p>
<tr>
<th bgcolor="#9999FF">Departements</th>
</>
</tr>
<?php $servername="localhost" ; $username="root" ; $password="" ; $dbname="dbms_pro" ; // Create connection $conn=n ew mysqli($servername, $username, $password, $dbname); // Check connection if ($conn->connect_error) { die("Connection failed: " . $conn->connect_error); } $sql = "SELECT dep_name FROM department"; $result = $conn->query($sql); if ($result->num_rows > 0) { // output data of each row while($row = $result->fetch_assoc()) { echo "
<tr>
<td department:>" . $row["dep_name"]. "</tr>
</td>"; } } else { echo "0 results"; } $conn->close(); ?>
</table>
</html>
你已經有很多註釋代碼'$康恩= N EW mysqli'例如和那裏面有一個空間,這是無效的語法'
回答
有基本的HTML一個標籤,使超鏈接,這是一個(http://www.w3schools.com/tags/tag_a.asp):
您需要遍歷數組,並添加一個唯一的ID href屬性來製作你想要的。下面的示例代碼,但是將html和php混合在一個文件中並不好。
來源
2015-04-20 14:04:03 vanadium23
不使用w3fools作爲引文來源。僅僅因爲他們首先在谷歌搜索結果並不意味着他們是一個很好的資源,這只是意味着他們浪費了大量的搜索引擎優化資金,而不是改善他們的內容。 –
什麼來源更好用? – vanadium23
mozilla的MDN網站非常好,或者您可以直接找到源代碼並鏈接到W3C html規範。 –
相關問題