【问题标题】:Tag cloud using php and mysql - how to link a new page using the mysql column name使用 php 和 mysql 标记云 - 如何使用 mysql 列名链接新页面
【发布时间】:2017-10-05 15:34:56
【问题描述】:

我会尽我所能来表达这句话。我已经添加了指向我需要帮助的页面的链接,它们也是那里的说明。我是php新手,需要帮助,谢谢。

P.S. 
I would like to keep the code I have unless you have a better one.

我的问题 --- 我用我的数据库表中的单词创建了按钮。我需要知道的是如何将链接按钮添加到您单击的单词,此链接将打开我的articlestagresults.php 页面并显示被选中的单词以及列出相应的文章到他们从标签云中选择的词。请查看我的两个网页,看看我要做什么。 这是我的两页,其中包含注释,以更好地说明我的意思。 https://livinghisword.org/articlestagresults.php ---- https://livinghisword.org/articlestagcloud.php 在此处输入代码 这是 articletagcloud.php 的代码 --- 下面

$sql = mysqli_query($db_conx, "SELECT word FROM articles GROUP BY word ORDER BY word ASC");

while ($row = mysqli_fetch_array($sql)) {
$word = $row['word'];

ksort($word);

echo "<div class='cloudbox tag'>$word</div>";
} 

非常感谢您提供的所有帮助!

【问题讨论】:

    标签: php mysql hyperlink tags cloud


    【解决方案1】:

    你只需要像这样将单词包裹在锚标记中

    echo "<div class='cloudbox tag'><a href = 'articlestagresults.php?word=" . $word . "'> " . $word . "</a></div>";
    

    articlestagresults.php 中,您可以简单地通过print_r($_GET['word']); 获取单词,这将为您提供上一页中选择的单词。

    articlestagresults.php

    $word = $_GET['word'];
    $sql = mysqli_query($db_conx, "SELECT * FROM articles WHERE word = '$word'");
    while ($row = mysqli_fetch_array($sql)) {
        print_r($row);// It will contain the row data
        //SHOW the HTML
    } 
    

    【讨论】:

    • @Jennifer 很高兴我能帮上忙。
    • 这很棒,它现在已链接并在新页面上显示单词。 ------ 因为你的帮助,我快到了。您能否告诉我如何根据articlestagresults.php 中的该词列出所有帖子。我不确定如何添加 php 代码并根据他们选择的单词列出所有帖子。任何帮助都会很棒!谢谢你:)
    • @Jennifer 很高兴为您提供帮助,欢迎来到 Stack Overflow。如果此答案或任何其他答案解决了您的问题,请将其标记为已接受
    • 是的,我正在运行,您可以查看一下。相同的位置livinghisword.org/articlestagresults.php 和我的标签位于livinghisword.org/articles.php --------------------- 非常感谢!!!!没有你的帮助,我不可能做到这一点,非常感谢:)
    【解决方案2】:

    我会为此建议一个简单的 javascript 函数,例如:

    <script type='text/javascript'>
        function bindEvents(){
            var col=document.querySelectorAll('div.cloudbox');
            if( col ){
                for( var n in col ){
                    if( col[ n ].nodeType==1 ){
                        col[n].addEventListener('click',function(e){
                            location.href='/articlestagresults.php?word='+this.innerHTML;
                        }.bind( col[ n ] ), false );
                    }
                }
            }
        }
        document.addEventListener('DOMContentLoaded', bindEvents, false );
    </script>
    

    这应该将word=value 字符串附加到查询字符串中——因此您的sql 将使用$_GET['word'] 的值来处理请求。

    您可以通过多种方式执行此操作 - 您可以使用 POST 提交表单,而不是使用 GET,这会将浏览器中的 url 保留为 https://livinghisword.org/articlestagresults.php

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-09-05
      • 1970-01-01
      • 2012-11-01
      • 2016-01-10
      • 1970-01-01
      • 1970-01-01
      • 2011-07-06
      相关资源
      最近更新 更多