Mysql、Php 和 Javascript 的动态导航链接

Dynamic navigation links with Mysql, Php and Javascript

我的 Javascript 功能确实有效,但不适用于此代码。

我显示了所有内容,但是导航链接不会以我的 Iframe 为目标。

有人能解释一下我的代码有什么问题吗?

这是我的代码:

function goto(url) { 
           document.getElementById("contentFrame").contentWindow.location.replace(url);
           }
</script>

<title>SOLSTEN</title>
</head>    
<body>    
<div id="rubrik"><h1>SOLSTEN</h1></div>         
    <?php
$mysqli = new mysqli('localhost', 'root', '', 'solsten');
            $sql = "select distinct productcategory from products";
            $result = $mysqli->query($sql);
                    echo "<div id='menu'>";
    while($myRow = $result->fetch_array())
                    {
                        echo "<ul>";
                        echo "<li style='display: inline;'><a href='javascript:void(0)' onclick='goto('imagegallery.php?category=".$myRow['productcategory']."')'> <h4>".$myRow["productcategory"]."</h4></a> </li>";
                        echo "</ul>";

                        } 
                    echo "</div>";  
    ?>

</div> 
     <div class='content'   >

<iframe src="imagegallery.php?category=Armband" scrolling="no" height='100%' width='100%' marginwidth='0' marginheight='0' scrolling='auto' onload='' allowtransparency='false'   id="contentFrame"></iframe>"

</div>

我得到了这张图片上我的导航链接的源代码。 >> http://test.mehmetakb.se/solsten1.jpg

您可以设置iframe的src属性。

function goto(url) { 
           document.getElementById("contentFrame").src = url;
           }

已更新:

您的 PHP 代码有误。 使用此代码更改 A 标签:

onclick=\"goto('imagegallery.php?category=".$myRow['productcategory']."')\"

注意斜线..如果你在产品类别中有斜线,你必须添加一些反斜线与 addslashes PHP 功能,或者更好的方法是使用 PHP rawurlencode 为了以 URL 格式编码所有字符..