【发布时间】:2017-09-26 03:24:01
【问题描述】:
大家早上好, 我执行 php mysqli 以获取 sql 中的前 5 个计数国家。然后我使用 jquery get 从 php 脚本中获取数据。最后,我想用 get jquery 填充 HTML 表。我只会得到 5 个国家,但是我尝试用这些数据填充 html 表,输出如下所示。
malaysia united states united kindgom singapore netherlands
gettopfive.php
<?php
include 'config.php';
$con = mysqli_connect ($dbhost, $dbusername, $dbpassword) or die ('Error in connecting: ' . mysqli_error($con));
//Select the particular database and link to the connection
$db_selected = mysqli_select_db($con, $dbname ) or die('Select dbase error '. mysqli_error());
//Make A SQL Query and link to the connection
$topfivecountries = mysqli_query($con,"SELECT `country.src` FROM `attackview` WHERE `device.type`='snort' AND `country.src` IS NOT NULL GROUP BY `country.src` ORDER by count(*) DESC LIMIT 5");
while ($row = mysqli_fetch_assoc($topfivecountries))
{
echo $row["country.src"]. "\n";
}
mysqli_free_result($topfivecountries);
mysqli_close($con);
?>
php 脚本的输出
malaysia
united states
united kindgom
singapore
netherlands
jquery 获取 app.js
$.get({
url: 'gettopfive.php',
dataType: 'text',
success: gettopfive
});
function getfive(val) {
$('#getfive').html(val);
}
html代码
<script src="js/app.js"></script>
<table id="getfive">
<tr><td></td><tr>
<tr><td></td><tr>
<tr><td></td><tr>
<tr><td></td><tr>
<tr><td></td><tr>
</table>
我的输出不是我想要的 我想要这样的东西。
malaysia
united states
united kindgom
singapore
netherlands
获取数据的方法是否正确???如果是错误的,请向我解释如何做?谢谢。。
【问题讨论】:
-
你能把php脚本的输出(数据库调用)贴在这里,这样我就可以从那里工作了吗?
-
我认为你最好使用
$.load()来完成你的需求,而不是$.get() -
@sbr 我已经更新了。你可以在上面检查
-
@Azhar 只是为了确认结果是多行字符串,对吗?
-
@TaufikNurRahmanda,我想知道你为什么建议使用 $.load() 而不是 $.get()
标签: javascript php jquery html