...

View Full Version : Problem in displaying the fetched data from db On MouseOver in a table



yollow
07-26-2010, 08:48 AM
Hi all,

I have a code that will fetch out the data from database OnMouseOver. But it is working fine if don't add table on the div which will come OnMouseOver. If i try to show the fetched data in table then the code doesn't work. Please someone help me with this.

Here is my code:





<script type="text/javascript" language="JavaScript">

var cX = 0; var cY = 0; var rX = 0; var rY = 0;
function UpdateCursorPosition(e){ cX = e.pageX; cY = e.pageY;}
function UpdateCursorPositionDocAll(e){ cX = event.clientX; cY = event.clientY;}
if(document.all) { document.onmousemove = UpdateCursorPositionDocAll; }
else { document.onmousemove = UpdateCursorPosition; }
function AssignPosition(d) {
if(self.pageYOffset) {

rX = self.pageXOffset;
rY = self.pageYOffset;
} else if (document.documentElement && document.documentElement.scrollTop) {

rX = document.documentElement.scrollLeft;
rY = document.documentElement.scrollTop;
} else if (document.body) {

rX = document.body.scrollLeft;
rY = document.body.scrollTop;
}
if(document.all) {
cX += rX;
cY += rY;
}

d.style.left = (cX+10) + "px";
d.style.top = (cY+10) + "px";
}
function HideContent(d) {
if(d.length < 1) { return; }
document.getElementById(d).style.display = "none";
}
function ShowContent(d) {
if(d.length < 1) { return; }
var dd = document.getElementById(d);
AssignPosition(dd);
dd.style.display = "block";
}
function ReverseContentDisplay(d) {
if(d.length < 1) { return; }
var dd = document.getElementById(d);
AssignPosition(dd);
if(dd.style.display == "none") { dd.style.display = "block"; }
else { dd.style.display = "none"; }
}
//-->
</script>

</head>

<body>
<table align="center" width="300px"/>
<tr>
<td>MakeID</td>
<td>Make</td>
<td>Veh Type</td>
</tr>
<?php
$conn = mysql_connect ('localhost', 'root', '');
mysql_select_db ('my_db', $conn);

function create_div($width, $height, $fields, $table, $w_field, $w_value, $unique) {
$f = implode("`, `", $fields);
$sql = "SELECT `$f` FROM `$table` WHERE `$w_field` = '$w_value'";
$res = mysql_query($sql) or die(mysql_error());
$div = "<div align=center id=\"data".$unique."\" style=\"display:none; position:absolute; border-style:solid; background-color:white; padding: 10px; width:".$width."px; height:".$height."px\" />\n";

$div .= '<table width="100%" cellpadding="4" cellspacing="2">';
$div .= '<tr><th>Serial</th><th>First Name</th><th>Email</th></tr>';

while($r = mysql_fetch_assoc($res)){
$div .= '<tr>';
$div .= '<td>'.$r['id'].'</td>';
$div .= '<td>'.$r['firstname'].'</td>';
$div .= '<td>'.$r['email'].'</td>';

$div .= "</tr>";
$div .= "</table>";
$div .= "</div>\n";
return $div;
}

$sql = "SELECT * FROM name";
$res = mysql_query($sql) or die(mysql_error());
$i=0;
$fields = array("id", "firstname", "email");
while($r = mysql_fetch_assoc($res)){
echo create_div("300", "200", $fields, "admin", "id", $r['id'], $i);
?>
<tr>
<td><?php echo $r['id']; ?></td>
<td><a onmouseover="ShowContent('data<?php echo $i; ?>'); return true;" onmouseout="HideContent('data<?php echo $i; ?>'); return true;" href="#"><?php echo $r['name'];?></a>
</td>
<td><?php echo $r['desc']; ?></td>
</tr>
<?php
$i++;
}
?>
</table>
</body>
</html>

abduraooft
07-26-2010, 09:09 AM
If i try to show the fetched data in table then the code doesn't work. That's too vague. Are you getting any php/javascript error in your browser?

yollow
07-26-2010, 09:33 AM
No, I'm not getting any error. in my browser.

Pls take a look at my page
http://lovelymad.co.cc/test/onmouse/

If you need any thing else to know pls ask me.

Thanks.

Old Pedant
07-27-2010, 02:07 AM
Well, for starters, your HTML is illegal.

You can't put a <div> inside of a <table> unless it is in turn inside a <td> or <th>.

All of your <div>s there should be either before or after the <table>.

When I moved them all *before* the <table>, they all worked just fine.

You are also missing the <html> and <head> tags.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum