为什么我的<a href="" link="" work?=""

时间:2017-01-25 16:13:01

标签: php html

="" When i click the link , it cant work.

These are my codes:

if (mysql_num_rows($sql1)) {
    echo"<table>";
    while ($row1 = mysql_fetch_array($sql1)) {
        if($row1['topic_id'] == $row['topic_id']){
            echo "<tr><th><font color='blue'>".$row1['topic_name']."</th></tr> </font>";
            echo"<a href='postreply.php?cat_id='$cat_id'&topic_id='$topic_id'&topic_creator='$topic_creator''>hi</a>";
        }
    }
    echo "<tr><td>".$row['post_content']."</td></tr>";
    echo"</table><hr>";
}

4 个答案:

答案 0 :(得分:1)

你的报价打破了代码, 您将需要转义双引号,因此它们不会被读作PHP代码。您可以通过在它们之前键入\字符来完成此操作。

在上面的代码中,修改如下:

echo"<a href='postreply.php?cat_id='$cat_id'&topic_id=\"$topic_id'&topic_creator=\"$topic_creator''>hi</a>";

答案 1 :(得分:0)

不需要多个class MyFilter implements \Zend\Filter\FilterInterface { public function filter($value, array $context = null) { if ($array && isset($context['fieldName'])) { // do whatever } return $valueFiltered; } } '?之间的空格也可能导致问题

cat

答案 2 :(得分:0)

试试,

echo"<a href='postreply.php?cat_id=$cat_id&topic_id=$topic_id&topic_creator=$topic_creator'>hi</a>";

由于在href属性

中使用错误,您的代码正在崩溃

修改:

您仍然无法单击该元素,因为父元素#notificationContainer click事件侦听器返回false,这也会阻止子元素的默认操作。

您可以通过更改代码的侦听器代码或通过停止从子a到父#notificationContainer的事件传播来使链接工作。这将停止调用父单击事件侦听器,并将允许a元素的默认操作。

所以要么删除

$("#notificationContainer").click(function()
{
return false;
});

或添加以下代码以停止脚本中的传播。

$("#notificationContainer a").click(function(e)
{ 
   e.stopPropagation();
});

答案 3 :(得分:0)

不要在HTML中使用php echo "<h1>Don't Use This</h1>";标记,因为当您在较大的项目中使用这些标记时,这些可能会产生缩进问题,省略分号等等。尽量保持代码的良好格式。

另一方面,我建议你使用php类和对象,mysqli面向对象的预备语句。这将有助于更好的编码方式。

<?php    
if (mysql_num_rows($sql1)){
    ?>      
            <table>
    <?php
            while ($row1 = mysql_fetch_array($sql1)) {
                if($row1['topic_id'] == $row['topic_id']){
    ?>
                    <tr>
                        <th><font color='blue'><?php echo $row1['topic_name'];?></font></th>
                    </tr>
                    <a href="postreply.php?cat_id=<?php echo "cat_id=".$cat_id."&topic_id=".$topic_id."&topic_creator=".$topic_creator;?>">hi</a>
    <?php
                }
            }
    ?>
                    <tr>
                        <td><?php echo $row['post_content'];?></td>
                    </tr>
            </table>
            <hr>
    <?php
        }

    ?>