While loop with div-tags not working
Posted: Sun Jun 15, 2008 5:06 am
So my purpose is to get items from mysql database with while loop:
And after that, i need to create links for each item by name:
(Javascript code for showcontent etc. is at the beginning of the page and it works fine without that loop)
And yes, it does create it all like it should, visually atleast. But even if the code is right (viewed from firefox source), only first one works, rest doesnt work..
Here is the code for that javascript too, if you want to try it out:
Im getting desperate with this.. Help please 
Code: Select all
$i = "1";
//Connected to database already
$itemlist = mysql_query("SELECT * FROM items")
or die(mysql_error());
while($row = mysql_fetch_array( $itemlist )) {
$itam = $row['name'];Code: Select all
<a
"onmousemove="ShowContent('uniquename<? echo $i; ?>'); return true;"
"onmouseover="ShowContent('uniquename<? echo $i; ?>'); return true;"
"onmouseout="HideContent('uniquename<? echo $i; ?>'); return true;"
"href="javascript:ShowContent('uniquename<? echo $i; ?>')">
<? echo $itam; ?>
</a>
<div
id="uniquename<? echo $i; ?>"
style="display:none;
position:absolute;
border-style: solid;
background-color: white;
padding: 5px;">
<iframe src="item<? echo $i; ?>.php">
</div>
<?
$i++;
}
?>And yes, it does create it all like it should, visually atleast. But even if the code is right (viewed from firefox source), only first one works, rest doesnt work..
Here is the code for that javascript too, if you want to try it out:
Code: Select all
<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>