Now, I’m having output of some mysql table by PHP. I’m using “echo command” for displaying results.
I want an element within that echo to be displayed when I mouseover another element within that echo.
When I use javascript onmouseover function, it disappears the whole echo command’s output.
Please any1 tell me what is wrong & what I should do for this.
My code is below:
<head>
<title>Untitled Document</title>
<script language="javascript">
function remove()
{
document.getElementById('delete').style.display = "block";
}
</script>
</head>
<body>
<?php
$con = mysql_connect("localhost","me_user","123456");
if (!$con) {
die('Could not connect: ' . mysql_error());
}
mysql_select_db("my_db", $con);
$result = mysql_query("SELECT * FROM table ORDER BY serial desc");
while($row = mysql_fetch_array($result))
{
{
echo "<div id='show' onmouseover='javascript:remove();'>
<table border='0' cellpadding='4'>
<tr>
<td>".$row['fname']." ".$row['lname']." ".$row['content']
."<br>"
.$row['date']."
</td>
<td align='right'>
<div id='delete' style='display:none'>
<form method='post' action='delete.php id='delete''>
<input type='hidden' name='delete' value='".$row['serial']."'>
<a href='javascript:submit();'>x</a>
</form>
</div>
</td>
</tr>
</table>";
echo "</div>";
}
echo "<br><hr size='1' color='#DFDFDF'><br>";
}
mysql_close($con);
?>
</body>
</html>
As it’s clear from above code, the div with id delete is hidden in starting. I want then when I mouseover on the div with id show, the div with id delete should be shown.
Please somebody tell how it’s done, coz when I use javascript as in the above code the div with id show itself is disappeared & nothing else happens.
Please help me.
Thanks in advance
You need to give unique ID to each
<div>then use this ID to show/hide only one specific element.Most simple way is by adding the current index in the loop to the ID, then pass this index to the JS function.
I’m not familiar with PHP, but code should be something like:
Which will generate for example:
Then change the function call to:
Which will generate for example:
Then finally, change the function to:
Hope this makes sense, let me know if the logic is not clear enough.