我想要实现的是我们的表格显示了音频的持续时间。但它只是更新第一行中的数据。
到目前为止,我所做的是 - 首先显示表中mysql数据库的数据 - 列出该表中的项目
UserID
Name
Path
IsDir
edit
Duration
这些是我表格中的表格列,每列都显示正确的数据,但持续时间列仅在第1行更新
Here is the image of current table
现在我的<tr>
代码
<tbody>
<?php
$count=1;
$sel_query="Select * from table_name where isdir=0 ORDER BY id desc;";
$result = mysqli_query($conn,$sel_query);
while($row = mysqli_fetch_assoc($result)) { ?>
<tr><td align="center"><?php echo $count; ?></td>
<td align="center"><?php echo $row["name"]; ?></td>
<td align="center"><?php echo str_replace(' ', '%20', ($row["path"])); ?></td>
<td align="center"><?php echo $row["isdir"]; ?></td>
<td align="center">
<audio id="<?php echo $row["id"]; ?>" controls>
<source src=../..<?php echo str_replace(' ', '%20', ($row["path"])); ?> type="audio/mpeg">
</audio>
</td>
<td align="center">
<body onload="myFunction<?php echo $row["id"]; ?>();">
<audio id="<?php echo $row["id"]; ?>" controls>
<source src=../..<?php echo str_replace(' ', '%20', ($row["path"])); ?> type="audio/mpeg">
</audio>
<p id="<?php echo $row["name"]; ?>"></p>
<script>
function myFunction<?php echo $row["id"]; ?>() {
var x<?php echo $row["id"]; ?> = document.getElementById("<?php echo $row["id"]; ?>").duration;
document.getElementById("<?php echo $row["name"]; ?>").innerHTML = x<?php echo $row["id"]; ?>;
}
</script>
</body>
</td>
<td><a href="newadd.php?source=<?php echo $row["path"]; ?>&title=<?php echo $row["name"]; ?>">Edit</a>
</td>
<td align="center">
<a href="delete.php?id=<?php echo $row["id"]; ?>">Delete</a>
</td>
</tr>
<?php $count++; } ?>
</tbody>
答案 0 :(得分:0)
您没有将行ID传递给该函数。它在函数调用和声明参数时都在括号之外。
所以而不是:
shows
执行:
onload="myFunction<?php echo $row["id"]; ?>();"
function myFunction<?php echo $row["id"]; ?>()
答案 1 :(得分:0)
未经测试,但类似的东西可能会起作用:
<?php while ($row = mysqli_fetch_array($nquery)) { ?>
<tr>
<!-- ... -->
<td><a id="link<?php echo $row['id'] ?>"
href="newadd.php?source=<?php echo $row["path"]; ?>&title=<?php echo $row["name"]; ?>&duration=">Edit</a>
</td>
<td>
<audio id="myAudio<?php echo $row['id'] ?>"
onloadedmetadata="myFunction(<?php echo $row['id'] ?>);"
controls>
<source src=../..<?php echo str_replace(' ', '%20', ($row["path"])); ?> type="audio/mpeg">
</audio>
</td>
<td>
<p id="demo<?php echo $row['id'] ?>"></p>
</td>
</tr>
<?php } ?>
<script>
function myFunction(id) {
var x = document.getElementById("myAudio" + id).duration;
document.getElementById("demo" + id).innerHTML = x;
var a = document.getElementById("link" + id);
a.href += x;
}
</script>