Connect with Expertise | Find Experts, Get Answers, Share Insights

php onmouseover help please

 
Join Date: Jan 2010
Posts: 3
#1: Jan 3 '10
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

Expand|Select|Wrap|Line Numbers
  1. <script type="text/javascript" language="JavaScript">
  2. <!-- Copyright 2006,2007 Bontrager Connection, LLC
  3. // http://bontragerconnection.com/ and http://www.willmaster.com/
  4. // Version: July 28, 2007
  5. var cX = 0; var cY = 0; var rX = 0; var rY = 0;
  6. function UpdateCursorPosition(e){ cX = e.pageX; cY = e.pageY;}
  7. function UpdateCursorPositionDocAll(e){ cX = event.clientX; cY = event.clientY;}
  8. if(document.all) { document.onmousemove = UpdateCursorPositionDocAll; }
  9. else { document.onmousemove = UpdateCursorPosition; }
  10. function AssignPosition(d) {
  11. if(self.pageYOffset) {
  12.  
  13. rX = self.pageXOffset;
  14.  
  15. rY = self.pageYOffset;
  16. }
  17. else if(document.documentElement && document.documentElement.scrollTop) {
  18.  
  19. rX = document.documentElement.scrollLeft;
  20.  
  21. rY = document.documentElement.scrollTop;
  22. }
  23. else if(document.body) {
  24.  
  25. rX = document.body.scrollLeft;
  26.  
  27. rY = document.body.scrollTop;
  28.  
  29. }
  30. if(document.all) {
  31.  
  32. cX += rX;
  33.  
  34. cY += rY;
  35. }
  36. d.style.left = (cX+10) + "px";
  37. d.style.top = (cY+10) + "px";
  38. }
  39. function HideContent(d) {
  40. if(d.length < 1) { return; }
  41. document.getElementById(d).style.display = "none";
  42. }
  43. function ShowContent(d) {
  44. if(d.length < 1) { return; }
  45. var dd = document.getElementById(d);
  46. AssignPosition(dd);
  47. dd.style.display = "block";
  48. }
  49. function ReverseContentDisplay(d) {
  50. if(d.length < 1) { return; }
  51. var dd = document.getElementById(d);
  52. AssignPosition(dd);
  53. if(dd.style.display == "none") { dd.style.display = "block"; }
  54. else { dd.style.display = "none"; }
  55. }
  56. //-->
  57. </script>
  58. <html>
  59. <head><title>Community in Alabama</title></head>
  60. <body>
  61. <table>
  62. <tr><td valign="top" height="100%" style="width: 183px" align="center">
  63.         <a href="http://bytes.com/Alabama/Auburn/index.htm">EverybodysList<p style="margin-top: 0">Auburn</p></a>
  64.         <a href="http://bytes.com/submit/post.php" target="_blank">Post to Artists</a>
  65.         <p><a href="http://bytes.com/account.htm">My Account</a></p>
  66.         <p><a href="http://bytes.com/terms.htm">Terms of Use</a></p>
  67.         <p><a href="http://bytes.com/scams.htm">About Scams</a></p>
  68.         <p><a href="http://bytes.com/feedback.htm">Contact Us</a></p>
  69.         <hr>
  70.         <img src="http://bytes.com/images/alabama.gif" alt="Alabama Flag" width="150" height="150">
  71.         <td valign="top"><font color="red">All Alabama</font><span style="visibility: hidden"> <a href=../../Auburn/Community/Al/tocprot.htm>Auburn</a>
  72.         <a href="http://bytes.com/Birmingham/Community/Al/tocproto.htm">Birmingham</a> 
  73.         <a href="http://bytes.com/Columbus/Community/Al/tocproto.htm">Columbus</a> 
  74. <a href="http://bytes.com/Dothan/Community/Al/tocproto.htm">Dothan</a> 
  75.         <a href="http://bytes.com/Florence/Community/Al/tocproto.htm">Florence</a> 
  76.         <a href="http://bytes.com/Gadsen/Community/Al/tocproto.htm">Gadsen</a> 
  77. <a href="http://bytes.com/Huntsville/Community/Al/tocproto.htm">Huntsville</a> 
  78.         <a href="http://bytes.com/Mobile/Community/Al/tocproto.htm">Mobile</a> 
  79.         <a href="http://bytes.com/Montgomery/Community/Al/tocproto.htm">Montgomery</a> 
  80. <a href="http://bytes.com/Tuscaloosa/Community/Al/tocproto.htm">Tuscaloosa</a></span>
  81. <?php 
  82. $user = ('account');
  83. $pass = ('account');
  84. $host = ('localhost');
  85. $link = mysql_connect('localhost', 'account', 'account'); 
  86. if (!$link) { 
  87.     die('Could not connect: ' . mysql_error()); 
  88. mysql_select_db("user", $link);
  89.  
  90. //Search criteria
  91. ?>
  92. <form action=search.php action=post><table>
  93. <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!>
  94. </table></form><hr><table width="100%">
  95.     <td align="left" width="20%">Date</td>
  96.     <td align="left" width="40%">Title</td>
  97.     <td align="Center" width="20%">Price</td>
  98.     <td align="Center" width="20%">Location</td>
  99.  
  100. <?php
  101. //database connection here
  102. $user = ('account');
  103. $pass = ('account');
  104. $host = ('localhost');
  105. $link = mysql_connect('localhost', 'account', 'account'); 
  106. if (!$link) { 
  107. mysql_select_db("user", $link);
  108.  
  109. function create_div($width, $fields, $table, $w_field, $w_value, $unique){
  110. $f = implode("`, `", $fields);
  111. $sql = "SELECT Description FROM post";
  112. $link = mysql_query($sql) or die(mysql_error());
  113. $div = "<div id=\"data".$unique."\" style=\"display:none; position:absolute; border-style:none; background-color:white; padding: 0px; width:".$width."px\" />\n";
  114.   while($r = mysql_fetch_assoc($link)){
  115.     foreach($fields as $name){
  116.     $div .= $r[$name]." ";
  117.     }
  118.   $div .= "<br />";
  119.   }
  120. $div .= "</div>\n";
  121. return $div;
  122. }
  123.  
  124. $sql = "SELECT * FROM post";
  125. $link = mysql_query($sql) or die(mysql_error());
  126. $i=0;
  127. $fields = array("Title", "Description");
  128. while($r = mysql_fetch_assoc($link)){
  129.   echo create_div("200", $fields, "models", "Title", $r['Title'], $i);
  130. ?>
  131.        <tr>
  132.        <td><?php echo $r['Date Created']; ?></td>
  133.        <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>
  134.  
  135.     <td>$<?php echo $r['Price']; ?></td>
  136.     <td><?php echo $r['Location']; ?></td></tr>
  137. <?php
  138. $i++;
  139. }
  140. ?>

Dormilich's Avatar
E
M
C
 
Join Date: Aug 2008
Location: Leipzig, Germany
Posts: 5,367
#2: Jan 3 '10

re: php onmouseover help please


well, your PHP function that fetches the description indeed outputs all descriptions for every title. why you wrote that function, I don’t understand, since the correct description is included in the original resultset.

PS. JavaScript is not at fault here, it only shows the results.

PPS. if (document.all) will also be triggered in Opera
 
Join Date: Jan 2010
Posts: 3
#3: Jan 3 '10

re: php onmouseover help please


What do i have to change? Sorry, I'm still new to this and found the js script online, the script itself is working but the popup should only display the contents of that row.
Dormilich's Avatar
E
M
C
 
Join Date: Aug 2008
Location: Leipzig, Germany
Posts: 5,367
#4: Jan 3 '10

re: php onmouseover help please


change your PHP so that it only prints the correct description.
 
Join Date: Jan 2010
Posts: 3
#5: Jan 4 '10

re: php onmouseover help please


can you tell me where to look? I'm not asking for you to do it for me, but I have no idea where to start as its working but displaying every description record
Dormilich's Avatar
E
M
C
 
Join Date: Aug 2008
Location: Leipzig, Germany
Posts: 5,367
#6: Jan 4 '10

re: php onmouseover help please


my personal opinion – discard create_div(). all you need should be fetched in line 126. a simple div (line 135, having a class to trigger the JavaScript) holding the description should do.
Reply