在onclick函数后显示从数据库中检索的推文 [英] Display tweets retrieved from database after onclick function

查看:78
本文介绍了在onclick函数后显示从数据库中检索的推文的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为我的应用程序使用JavaScript,PHP和HTML。我有一个包含推文的SQL数据库。在点击关键字(连接到超级树)后,我需要从数据库查询并显示推文。我已经研究并尝试在index.php的myFunction()中包含一个外部php文件(generatetweets.php)。然而,它不起作用。任何人都可以启发我或任何参考我的指导?提前谢谢。



提取的example2.js,其中child.name引用超树中的关键字



 onComplete: function (){
// Log.write(done);

// 使关系列表显示在右栏中。
// 加载相关TWE的关键字的ONCLICK功能
var node = ht.graph.getClosestNodeToOrigin( 当前);
var html = < div> < b>关键字: + node.name + < / b>< / div> ;;
html + = < ul>;
node.eachAdjacency( function (adj){
var child = adj。 nodeTo;
var childName = child.name;
html + = ' < span class =code-string><aönclick=myFunction('
+ ' ' ' + child.name +' ' ' + ' )>' + child.name + ' < / a> ;;

});
html + =br />;
$ jit.id('
inner-details ' )。innerHTML = html;
}







generatetweets.php



 <?php  
/ / 连接数据库
包括 mysqli.connect.php;

// 创建SQL语句以检索
中的所有内容 // users表
$ sql = SELECT * FROM post WHERE content LIKE'%school%'ORDER BY date DESC ;

// 运行查询
$ result = $ mysqli-> query($ sql);

// 检查错误
if ($ mysqli-> errno)
{
error_log($ mysqli-> error);
echo < br />出了点问题;
exit();
}


?>

< !DOCTYPE html >
< html xmlns = < span class =code-keyword> http://www.w3.org/1999/xhtml
xml:lang = zh lang = zh >
< head >
< meta http-equiv = 内容类型 内容 = text / html; charset = UTF-8 / > ;
< head >
< / head >
< body >
<? php
// 检查首先是否有记录
if ($ result-> num_rows < 1)
{
echo < h3>未找到任何记录< / h3>;
}


// 迭代记录
$ counter = 0 ;
// 使用fetch_array一次返回一行
while( $ row = $ result-> fetch_array(MYSQLI_ASSOC))
{
?>
< 表格 >
< tr id = tweetlist >
< td 样式 = width:50px >
<! - 名称在这里 - >
<! - < img id =img<?= $ counter?> style =padding-right:5pxsrc =<?= $ row [displaypicture]?>>< / img> - >

< / td >
< td >
<! - 电子邮件文本字段在此处 - >
< span id = date<?= $ counter?> s tyle = 颜色:#CCFF33 > [<? = $ row [ 日期] ?> ] < / span >
< span id = name<?= $ counter?> > @ <? = $ row [ username] ?> < / spa n >
< span id = emailTxt<?= $ counter?> > <? = $ row [ content] ?> < span / >
< / td >
< / tr >
< / table >
< br / >
<? php
$ counter ++;
}
$ result-> free();
$ mysqli-> close();
?>

< / body >









提取index.php,显示div中的推文demo



 <   body     onload   =  init(); >  

<! - 标题 - >
< div id = header class = 容器 >

< span class =code-keyword><! - 徽标 - >
< h1 id = logo > < a href = index.php > 心情< / a > < / h1 > <! - 来自style-n1.css的徽标 - >

< div id = center-container >
< div id = infovis > < / div >
< / div >

< div id = 右容器 >
< div id = inner-details > < / div >
< div id = log > < / div >
< div id = node_name > < / div >
< div id = demo 样式 = padding-removed 50px >

< script type = text / javascript >
函数 myFunction(){

$( #demo)。load( generatetweets.php);

}
< / script >
< / div >
< / div >
< < span class =code-leadattribute> / div >

< ; / body >



$ b





Hypertree引自http://philogb.github.io/jit/ static / v20 / Jit / Examples / Hypertree / example2.html

解决方案

jit.id(' inner-details ' )。innerHTML = html;
}







generatetweets.php



 <?php  
/ / 连接数据库
包括 mysqli.connect.php;

// 创建SQL语句以检索
中的所有内容 // 用户表

sql = SELECT * FROM post WHERE content LIKE'%school% 'ORDER BY date DESC;

// 运行查询


result =


I am using JavaScript, PHP and HTML for my application. I have a SQL database that contains tweets. I need to query from database and display tweets after the keyword (connecting to a hyper tree) is clicked. I have researched and tried to include an external php file (generatetweets.php) inside myFunction() at index.php. However it's not working. Anyone can enlighten me or any reference for me to guide? Thank you in advance.

Extracted example2.js, where child.name refers to the keyword from hyper tree

onComplete: function() {
            //Log.write("done");

            //Make the relations list shown in the right column.
			//ONCLICK FUNCTION FOR KEYWORDS TO LOAD RELATED TWEETS
            var node = ht.graph.getClosestNodeToOrigin("current");
            var html = "<div><b>Keyword: " + node.name + "</b></div>";
            html += "<ul>";
            node.eachAdjacency(function(adj){
                var child = adj.nodeTo;
				var childName=child.name;
				html += '<a önclick="myFunction('+'''+child.name+'''+')">'+child.name + '</a>;
				
            });
            html += "br />";
            $jit.id('inner-details').innerHTML = html;
}




generatetweets.php

<?php
// connect to the database
include "mysqli.connect.php";

// create your SQL statment to retrieve everything from
// the users table
$sql = "SELECT * FROM post WHERE content LIKE '%school%' ORDER BY date DESC";

// run the query
$result = $mysqli->query($sql);

// check for error
if ($mysqli->errno)
{
  error_log($mysqli->error);
  echo "<br />Something's wrong";
  exit();
}


?>

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<head>
</head>
<body>
    <?php
        // Check if there are records in the first place
            if ($result->num_rows < 1)
                {
                    echo "<h3>No records found</h3>";
                }


            // Iterate through the records
            $counter = 0;
            // Use fetch_array to get rows returned one at a time
            while($row = $result->fetch_array(MYSQLI_ASSOC))
                {
    ?>  
                <table>
                    <tr id="tweetlist">
                        <td style="width:50px">
                            <!-- name goes here -->
                            <!--<img id="img<?=$counter?>" style="padding-right:5px" src="<?=$row["displaypicture"]?>"></img>-->

                        </td>
                        <td>
                            <!-- email textfield goes here -->
                            <span id="date<?=$counter?>" style="color:#CCFF33">[<?=$row["date"]?>] </span>
                            <span id="name<?=$counter?>">@<?=$row["username"]?>: </span>
                            <span id="emailTxt<?=$counter?>"><?=$row["content"]?> <span/>
                        </td>
                    </tr>
                </table>
                <br/>
                <?php
                    $counter++;
                }
                    $result->free();
                    $mysqli->close();
                ?>

</body>





Extracted index.php, to display tweets in div "demo"

<body onload="init();">

<!-- Header -->
<div id="header" class="container">

    <!-- Logo -->
    <h1 id="logo"><a href="index.php">Mood</a></h1>  <!-- logo from style-n1.css -->

    <div id="center-container">
        <div id="infovis"></div>    
    </div>

    <div id="right-container">
        <div id="inner-details"></div>
        <div id="log"></div>
        <div id="node_name"></div>  
        <div id="demo" style="padding-removed 50px">

            <script type="text/javascript">
                function myFunction() {

                    $("#demo").load("generatetweets.php");  

                }
            </script>
        </div>
    </div>
</div>

</body>






Hypertree is referenced from http://philogb.github.io/jit/static/v20/Jit/Examples/Hypertree/example2.html

解决方案

jit.id('inner-details').innerHTML = html; }




generatetweets.php

<?php
// connect to the database
include "mysqli.connect.php";

// create your SQL statment to retrieve everything from
// the users table


sql = "SELECT * FROM post WHERE content LIKE '%school%' ORDER BY date DESC"; // run the query


result =


这篇关于在onclick函数后显示从数据库中检索的推文的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆