php - mysql_fetch_array's div onmouseover only works for first result -
i new on website , hope you'll answer soon.
i want remove icon show when users hover on selected friend, appears on mysql_fetch_array's first result. doesn't work others. can help? i've heard it's being done foreach function don't know how use it, because i'm new @ php.
here codes.
php:
$q = mysql_query("select * `users`"); while ($row = mysql_fetch_array($q)) { echo '<div id="friends" onmouseover="showremove();" onmouseout="hideremove();">'; echo '<div id="fillexit"></div>'; echo '<div id="showexit"></div>'; echo '</div>'; }
javascript:
function showremove() { var l=document.getelementbyid("showexit"); var s=document.getelementbyid("fillexit"); l.style.display = 'block'; s.style.display = 'none'; } function hideremove() { var p=document.getelementbyid("showexit"); var o=document.getelementbyid("fillexit"); p.style.display = 'none'; o.style.display = 'block'; }
css:
#fillexit { width:12px; height:12px; float:right; } #showexit { width:12px; height:12px; background-color:#000000; float:right; text-align:center; display:none; }
i'd appriciate help.
it because html echoed php script have same ids row elements.
you should create unique id using counter or , change js accordingly. may can pass id js method find elements on page.
php
$q = mysql_query("select * `users`"); $count = 0; while ($row = mysql_fetch_array($q)) { echo '<div id="friends'.$count.'" onmouseover="showremove('.$count.');" onmouseout="hideremove('.$count.');">'; echo '<div id="fillexit'.$count.'"></div>'; echo '<div id="showexit'.$count.'"></div>'; echo '</div>'; $count = $count + 1; }
js
function showremove(id) { var l=document.getelementbyid("showexit" + id); var s=document.getelementbyid("fillexit" + id); l.style.display = 'block'; s.style.display = 'none'; } function hideremove() { var p=document.getelementbyid("showexit" + id); var o=document.getelementbyid("fillexit" + id); p.style.display = 'none'; o.style.display = 'block'; }
Comments
Post a Comment