While loop with div-tags not working

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
desmi
Forum Commoner
Posts: 64
Joined: Sun Jun 15, 2008 4:55 am

While loop with div-tags not working

Post by desmi »

So my purpose is to get items from mysql database with while loop:

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'];
And after that, i need to create links for each item by 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&#058;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++;
}
?>
(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:

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>
Im getting desperate with this.. Help please :)
User avatar
superdezign
DevNet Master
Posts: 4135
Joined: Sat Jan 20, 2007 11:06 pm

Re: While loop with div-tags not working

Post by superdezign »

desmi wrote:

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&#058;ShowContent('uniquename<? echo $i; ?>')">
<? echo $itam; ?>
</a>
Why do you have so many quotation marks? The highlighting should show you what is wrong.
desmi
Forum Commoner
Posts: 64
Joined: Sun Jun 15, 2008 4:55 am

Re: While loop with div-tags not working

Post by desmi »

Ah, thanks, problem solved, what i was missing was </iframe> .. :oops:
Post Reply