Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New to the CF scene
    Join Date
    May 2010
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Problem in displaying the fetched data from db On MouseOver in a table

    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:

    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>

  • #2
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,863
    Thanks
    160
    Thanked 2,224 Times in 2,211 Posts
    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?
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)

  • #3
    New to the CF scene
    Join Date
    May 2010
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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.

  • #4
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    26,525
    Thanks
    80
    Thanked 4,490 Times in 4,454 Posts
    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.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •