mysql的命令行没有正确显示结果.我的意思是一些表的列位于第一行的第二行.输出也分为两行.如何调整这些设置以便正确显示结果.
如果我有一个无序列表,如
<ul id="list">
<li>Helo World-1</li>
<li>Helo World-2</li>
<li>Helo World-3</li>
</ul>
Run Code Online (Sandbox Code Playgroud)
我想动态添加一个子列表项.在javascript中有没有任何方法可以做到这一点.我怎么能这样做 编辑 我需要一个下一级别的项目,也就是我在OP中提到的Helo World的子列表,就像下面的那样.这里还有一个问题是我需要将这些项目作为我代码的永久部分.
<ul id="list">
<li>Helo World-1</li>
<li>Helo World-2</li>
<li>Helo World-3</li>
<ul>
<li>One</li>
<li>Two</li>
</ul>
</ul>
Run Code Online (Sandbox Code Playgroud) 我已经将从php函数返回的xml对象转换为json格式,将其发送到js文件中.
function searchResults($q) { ...
$xml = simplexml_load_string($result);
return json_encode($xml); }
Run Code Online (Sandbox Code Playgroud)
我在js中收到/使用它
var msg_top = "<"+"?php echo searchResults('windows');"+"?"+">";
Run Code Online (Sandbox Code Playgroud)
然后我在php中接收它并解码.
$json = $_POST['msg_top'];
$msg = json_decode($json);
Run Code Online (Sandbox Code Playgroud)
现在我如何遍历它以获取我可以从xml对象(我转换为json)获得的某些属性的所有值.这是我遍历xml对象以获取其某些属性的所有值的方法:
foreach ($xml->entry as $status) {
echo $status->author->name.''.$status->content);
}
Run Code Online (Sandbox Code Playgroud)
如何从解码的json对象$ msg中获取所有这些值?
编辑
我尝试在相同的HTML,我使用js通过ajax接收&POST php搜索功能数据,我尝试按照代码循环浏览json in php.但它没有显示任何东西.
$obj = searchResults(testword);//serach function returns json encoded data
$obj = json_decode($obj, true);
$count = count($obj);
for($i=0;$i<$count;$i++)
{
echo $obj[$i][content];}// using xml for it, I get ouput like foreach ($xml3->entry as
// $status) {status->content}
Run Code Online (Sandbox Code Playgroud) 我有一段代码在IE中工作正常,但它不能在Firefox中运行.我认为问题在于我无法实施$('document').ready(function).我的json的结构类似于[{"options":"smart_exp"},{"options":"user_intf"},{"options":"blahblah"}].如果有人能看到我的代码并帮助我正确实现它,我将非常感激.这是我的代码:
<html><head>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2
/jquery.min.js"></script>
<script type="text/javascript" language="javascript">
$(document).ready(function() {
$.getJSON("http://127.0.0.1/conn_mysql.php", function (jsonData) {
$.each(jsonData, function (i, j) {
document.form1.fruits.options[i] = new Option(j.options);
});});
});
</script></head>
<body><form name="form1">
My favourite fruit is :
<select name="fruits" id="fruits" /></form></body>
</html>
Run Code Online (Sandbox Code Playgroud) 这是从mysql(一行)获取表值的php脚本.并将其作为JSON回应
<?php
$username = "user";
$password = "********";
$hostname = "localhost";
$dbh = mysql_connect($hostname, $username, $password) or die("Unable to
connect to MySQL");
$selected = mysql_select_db("spec",$dbh) or die("Could not select first_test");
$query = "SELECT * FROM user_spec";
$result=mysql_query($query);
$outArray = array();
if ($result) {
while ($row = mysql_fetch_assoc($result)) $outArray[] = $row;
}
echo json_encode($outArray);
?>
Run Code Online (Sandbox Code Playgroud)
这是用于接收和打印json数据的HTML文件.
src ="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"> // $('document').ready(function(){
function Preload() {
$.getJSON("http://localhost/conn_mysql.php", function(jsonData){
$.each(jsonData, function(i,j)
{ alert(j.options);});
});}
// });
</script></head>
<body onLoad="Preload()">
</body>
</html> >
Run Code Online (Sandbox Code Playgroud) 我正在尝试使用 chart.js 在 x.axix 上显示日期。我从数据库中作为 json 接收到两个值;时间戳和传感器读取。我想根据图表中的每个时间戳显示传感器读取的刻度。数据每隔几分钟定期更新一次。
这是时间戳的格式:
2018-12-07 12:45:17
Run Code Online (Sandbox Code Playgroud)
到目前为止,这是我的图表代码:
var ctx = document.getElementById ('myChart').getContext('2d');
var myChart = new Chart(ctx, {
type: 'line',
data: {
labels: time_Array, // example value 2018-12-07 12:45:17 .......
datasets: [{
label: 'Humidity',
data: meas_value_Array, //// example value 116, 120 110 ....
backgroundColor: "rgba(255,153,0,0.4)"
}]
},
options: {
scales: {
yAxes: [{
ticks: {
beginAtZero:true
}
}],
xAxes: [{
type: 'time',
time: {
unit: 'minute',
displayFormats: {
second: 'h:MM:SS',
minute: 'h:MM',
hour: 'hA',
day: 'MMM …Run Code Online (Sandbox Code Playgroud) 我在var data =<?php echo serialize($msg);?>;下面的代码中得到此错误.控制台还会引发未定义错误的数据.我在数据周围加上引号,然后出现这个错误,但第一个错误仍然存在.
EDITED
//Raw xml
$result = curl_exec($ch);
curl_close($ch);
$xml = simplexml_load_string($result);
return $xml;
}
?>
<head>
<script type="text/javascript" src="http://code.jquery.com/jquery-latest.min.js">
</script>
</head>
<body>
<script type="text/javascript"> <?php $msg = searchResults('windows');?>;
var data ="<?php echo serialize($msg);?>";
</script>
<script type="text/javascript">
$(document).ready(function()
{
$.ajax({
url: "script.php",
type: "POST",
data: data,
success: function(){
alert("success");
}
});
return false;
});
</script>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
我试图看到但无法找出任何问题
这是script.php
<?php
var_dump($_POST);
?>
Run Code Online (Sandbox Code Playgroud)
这是来自twitter的xml
var data =O:16:"SimpleXMLElement":5:{s:2:"id";s:43:"tag:search.twitter.com,2005:search/#DIYSe_D";s:4:"link";a:4:{i:0;O:16:"SimpleXMLElement":1:{s:11:"@attributes";a:3:{s:4:"type";s:9:"text/html";s:4:"href";s:45:"http://search.twitter.com/search?q=%23DIYSe_D";s:3:"rel";s:9:"alternate";}}i:1;O:16:"SimpleXMLElement":1:{s:11:"@attributes";a:3:{s:4:"type";s:20:"application/atom+xml";s:4:"href";s:58:"http://search.twitter.com/search.atom?q=%23DIYSe_D&rpp=100";s:3:"rel";s:4:"self";}}i:2;O:16:"SimpleXMLElement":1:{s:11:"@attributes";a:3:{s:4:"type";s:37:"application/opensearchdescription+xml";s:4:"href";s:40:"http://search.twitter.com/opensearch.xml";s:3:"rel";s:6:"search";}}i:3;O:16:"SimpleXMLElement":1:{s:11:"@attributes";a:3:{s:4:"type";s:20:"application/atom+xml";s:4:"href";s:84:"http://search.twitter.com/search.atom?q=%23DIYSe_D&rpp=100&since_id=7856019371724800";s:3:"rel";s:7:"refresh";}}}s:5:"title";s:25:"#DIYSe_D - Twitter Search";s:7:"updated";s:20:"2010-11-24T21:53:28Z";s:5:"entry";a:3:{i:0;O:16:"SimpleXMLElement":7:{s:2:"id";s:44:"tag:search.twitter.com,2005:7552404006371328";s:9:"published";s:20:"2010-11-24T21:53:28Z";s:4:"link";a:2:{i:0;O:16:"SimpleXMLElement":1:{s:11:"@attributes";a:3:{s:4:"type";s:9:"text/html";s:4:"href";s:50:"http://twitter.com/_smir/statuses/7552404006371328";s:3:"rel";s:9:"alternate";}}i:1;O:16:"SimpleXMLElement":1:{s:11:"@attributes";a:3:{s:4:"type";s:9:"image/png";s:4:"href";s:67:"http://s.twimg.com/a/1289849896/images/default_profile_5_normal.png";s:3:"rel";s:5:"image";}}}s:5:"title";s:59:"#DIYse_D DELIVERAB: twitter messages 2_inc 1, 19th …Run Code Online (Sandbox Code Playgroud) 我正在尝试从数据中删除异常值。在我的例子中,异常值是在箱线图上绘制时远离其余数据的值。删除异常值后,我会将数据保存在新文件中并运行一些预测模型以查看结果。它们与原始数据有多么不同。
我使用了一个教程并采用它来删除数据中的异常值。本教程使用箱线图来找出异常值。
当我在有异常值的列上运行它时,它工作得很好。但当我对没有异常值的列运行它时,它会引发错误。如何消除这个错误?
这是代码:
outlier_rem <- Data_combined #data-frame with 25 var, few have outliers
#removing outliers from the column
outliers <- boxplot(outlier_rem$var1, plot=FALSE)$out
#print(outliers)
ol <- outlier_rem[-which(outlier_rem$var1 %in% outliers),]
dim(ol)
# [1] 0 25
boxplot(ol)
Run Code Online (Sandbox Code Playgroud)
产生错误:
outlier_rem <- Data_combined #data-frame with 25 var, few have outliers
#removing outliers from the column
outliers <- boxplot(outlier_rem$var1, plot=FALSE)$out
#print(outliers)
ol <- outlier_rem[-which(outlier_rem$var1 %in% outliers),]
dim(ol)
# [1] 0 25
boxplot(ol)
Run Code Online (Sandbox Code Playgroud)