php onmouseover help please

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • jkershner
    New Member
    • Jan 2010
    • 3

    php onmouseover help please

    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++;
    }
    ?>
    Last edited by Dormilich; Jan 3 '10, 09:51 AM. Reason: Please use [code] tags when posting code
  • Dormilich
    Recognized Expert Expert
    • Aug 2008
    • 8694

    #2
    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

    Comment

    • jkershner
      New Member
      • Jan 2010
      • 3

      #3
      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.

      Comment

      • Dormilich
        Recognized Expert Expert
        • Aug 2008
        • 8694

        #4
        change your PHP so that it only prints the correct description.

        Comment

        • jkershner
          New Member
          • Jan 2010
          • 3

          #5
          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

          Comment

          • Dormilich
            Recognized Expert Expert
            • Aug 2008
            • 8694

            #6
            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.

            Comment

            Working...