I have a problem with some code. The proram allows me to copy from one lick one password that is sought on my BDDMysql. I have a script that allows me to copy the content of the html tag <P>, with a specific ID. All of that i got it inside of a while(mysqli_fetch_array($result)). So the problem is, when i click for copy one password, only i get the first one of the bdd copied on the clipboard.
<?php
$egest='SELECT * FROM gestion';
$result=mysqli_query($con,$egest);
while ($row = mysqli_fetch_array($result)){
//echo $row['subcat_nombre'];
?>
<script>
function copyToClipboard(element) {
var $temp = $("<input>");
$("body").append($temp);
$temp.val($(element).text()).select();
document.execCommand("copy");
$temp.remove();
}
</script>
<table class="estilo-ps">
<tr>
<td colspan="3" class="td-tit"><b><?php echo $row['gest_nombre'] ?></b></td>
</tr>
<tr class="tr-borders">
<th class="th-border-cent">Contrasenya</th>
</tr>
<tr class="tr-borders">
<td class="td-border-cent">
<center>
<p hidden="hidden" id="p1"><?php echo $row['gest_contra']; ?></p><br>
<p>clic per copiar la contrasenya</p>
<img src="img/key.png" class="copy" onclick="copyToClipboard('#p1')"/>
</center>
</td>
</tr>
<?php
}
?>
id="p1".$(element)will always return the first one, not the one in the same row that the user clicked on.<table>tag but no</table>. Do you really want to create a separate table for each row that the query returns?