I have a js script inside php code that is connected to mysql, the php code is listing the results from the query then, the onmouseover function is supposed to show the description of the title for that specific title, however, the mouseover is displaying all the descriptions for every title. Also, will you let me know if I have code in here that is not needed? I'm very new to php/js
Code:
<script type="text/javascript" language="JavaScript"> <!-- Copyright 2006,2007 Bontrager Connection, LLC // http://bontragerconnection.com/ and http://www.willmaster.com/ // Version: July 28, 2007 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> <html> <head><title>Community in Alabama</title></head> <body> <table> <tr><td valign="top" height="100%" style="width: 183px" align="center"> <a href="http://bytes.com/Alabama/Auburn/index.htm">EverybodysList<p style="margin-top: 0">Auburn</p></a> <a href="http://bytes.com/submit/post.php" target="_blank">Post to Artists</a> <p><a href="http://bytes.com/account.htm">My Account</a></p> <p><a href="http://bytes.com/terms.htm">Terms of Use</a></p> <p><a href="http://bytes.com/scams.htm">About Scams</a></p> <p><a href="http://bytes.com/feedback.htm">Contact Us</a></p> <hr> <img src="http://bytes.com/images/alabama.gif" alt="Alabama Flag" width="150" height="150"> <td valign="top"><font color="red">All Alabama</font><span style="visibility: hidden"> <a href=../../Auburn/Community/Al/tocprot.htm>Auburn</a> <a href="http://bytes.com/Birmingham/Community/Al/tocproto.htm">Birmingham</a> <a href="http://bytes.com/Columbus/Community/Al/tocproto.htm">Columbus</a> <a href="http://bytes.com/Dothan/Community/Al/tocproto.htm">Dothan</a> <a href="http://bytes.com/Florence/Community/Al/tocproto.htm">Florence</a> <a href="http://bytes.com/Gadsen/Community/Al/tocproto.htm">Gadsen</a> <a href="http://bytes.com/Huntsville/Community/Al/tocproto.htm">Huntsville</a> <a href="http://bytes.com/Mobile/Community/Al/tocproto.htm">Mobile</a> <a href="http://bytes.com/Montgomery/Community/Al/tocproto.htm">Montgomery</a> <a href="http://bytes.com/Tuscaloosa/Community/Al/tocproto.htm">Tuscaloosa</a></span> <?php $user = ('account'); $pass = ('account'); $host = ('localhost'); $link = mysql_connect('localhost', 'account', 'account'); if (!$link) { die('Could not connect: ' . mysql_error()); } mysql_select_db("user", $link); //Search criteria ?> <form action=search.php action=post><table> <tr><td>Search For:<td><input type=text name=subject><tr><td>Price:<td><font color=grey><input type=text name=MinPrice size=6><input type=text name=MaxPrice size=6></font><td><input type=submit value=Search!> </table></form><hr><table width="100%"> <td align="left" width="20%">Date</td> <td align="left" width="40%">Title</td> <td align="Center" width="20%">Price</td> <td align="Center" width="20%">Location</td> <?php //database connection here $user = ('account'); $pass = ('account'); $host = ('localhost'); $link = mysql_connect('localhost', 'account', 'account'); if (!$link) { } mysql_select_db("user", $link); function create_div($width, $fields, $table, $w_field, $w_value, $unique){ $f = implode("`, `", $fields); $sql = "SELECT Description FROM post"; $link = mysql_query($sql) or die(mysql_error()); $div = "<div id=\"data".$unique."\" style=\"display:none; position:absolute; border-style:none; background-color:white; padding: 0px; width:".$width."px\" />\n"; while($r = mysql_fetch_assoc($link)){ foreach($fields as $name){ $div .= $r[$name]." "; } $div .= "<br />"; } $div .= "</div>\n"; return $div; } $sql = "SELECT * FROM post"; $link = mysql_query($sql) or die(mysql_error()); $i=0; $fields = array("Title", "Description"); while($r = mysql_fetch_assoc($link)){ echo create_div("200", $fields, "models", "Title", $r['Title'], $i); ?> <tr> <td><?php echo $r['Date Created']; ?></td> <td><a onmouseover="ShowContent('data<?php echo $i; ?>'); return true;" onmouseout="HideContent('data<?php echo $i; ?>'); return true;" href="javascript:ShowContent('data<?php echo $i; ?>')"><?php echo $r['Title'];?></a> <td>$<?php echo $r['Price']; ?></td> <td><?php echo $r['Location']; ?></td></tr> <?php $i++; } ?>
Comment