我有一篇文章和一篇文章摘要的發佈日期的表格,這些表格是可點擊的,並且當您點擊它時應該進入編輯頁面。該文章應該在您點擊時填寫,以便您輕鬆編輯文本。我已經建立了表格行,但我認爲我需要從表格中獲取ID,以便知道編輯頁面應該填充的內容。PHP MySQL與表格行(可點擊)顯示數據
這裏是我當前的代碼:
<?php
include 'index.php';
include 'login2.php';
?>
<html>
<head>
<link rel="stylesheet" type="text/css" href="alleartikelen.css">
</head>
<body>
<h2> Widget news admin </h2>
<!-- Echo username -->
<?php
$user = $_SESSION['user'];
echo "<p>You are logged in as <b>$user</b>.</p>";
?>
<a class="logout" href="index.php">Log out </a>
<hr>
<h1> All Articles </h1>
<?php
$sql = "SELECT art_date, art_head FROM article";
$result = $conn->query($sql); //it makes the query
?>
<style>
.table td {
font-family: Merriweather, serif;
font-size: 16px;
padding: 10px 5px;
overflow: hidden;
word-break: normal;
}
.table th:first-child,
.table td:first-child {
width: 14%;
height: 10%;
}
td,th{
font-family: "Calibri ";
}
tr:nth-child(even){
background-color: #ddd;
}
tr:hover {
background-color: #F6F6F6;
}
th{
color:white;
}
.aa {
text-decoration: none;
color: inherit;
}
</style>
<section>
<div class="container">
<table class="table">
<tr>
<th>Publication date</th>
<th>Article</th>
</tr>
<?php
$res=$result->fetch_all(MYSQL_ASSOC); //Splitting all rows in arrays
$keys = array_keys($res[0]); //Arrays getting attached to $keys
// Make the results as rows
echo "<tbody>";
foreach($res as $rows)
{
echo "<tr>";
foreach($rows as $date)
{
echo "<td><a href='bewerkartikel.php'class ='aa'>$date</a>";
echo "</td>";
}
echo "</tr>";
}
echo "</tr>";
}
?>
</section>
</body>
</html>
你需要一個id/CSS添加到你想成爲可編輯的每個單元/容器。使用JavaScript,您需要爲每個可編輯的單元格/容器開發一個onclick監聽器。 Onclick顯示一個輸入字段或textarea。你可以使用一個id或css類。你需要的是一個相應的事件監聽器。儘管ID使事情變得更容易。 – AMartinNo1
你能告訴我怎麼樣?因爲我是初學者,不知道如何去做一些事情。 :/ – Realcookie
w3schools通常是一個好的開始:https://www.w3schools.com/js/js_htmldom_eventlistener.asp – AMartinNo1