php 如何从mysql输出数组用逗号分隔?
从数据库表中取出5个变量,$host1="127.0.0.1";$user1="root";$password1="";$id1=mysql_connect("$host...
从数据库表中取出5个变量,
$host1 = "127.0.0.1";
$user1 = "root";
$password1 = "";
$id1=mysql_connect("$host1","$user1","$password1") or die("Can't connect to the SQL-server");
mysql_select_db("dcs1",$id1);
$query1 = "select sj, dm000 from hist20120718 where substring(sj,15,2)='00' and substring(sj,18,2)='00'";
$result1 = mysql_query($query1,$id1);
while ($row = mysql_fetch_array($result1)) {
$sj =$row["sj"];
$dm000=$row["dm000"];
$ydata[] = $row[dm000];
}
print_r($ydata);
输出为 Array([0] => 188.869 [1] => 142.654 [2] => 139.888 [3] => 154.228 [4] => 175.21
[5] => 195.342)我想让他变为array(188.869,142.654,139.888,154.288,175.21)
怎么改程序呢,多谢高手了。辛苦辛苦 展开
$host1 = "127.0.0.1";
$user1 = "root";
$password1 = "";
$id1=mysql_connect("$host1","$user1","$password1") or die("Can't connect to the SQL-server");
mysql_select_db("dcs1",$id1);
$query1 = "select sj, dm000 from hist20120718 where substring(sj,15,2)='00' and substring(sj,18,2)='00'";
$result1 = mysql_query($query1,$id1);
while ($row = mysql_fetch_array($result1)) {
$sj =$row["sj"];
$dm000=$row["dm000"];
$ydata[] = $row[dm000];
}
print_r($ydata);
输出为 Array([0] => 188.869 [1] => 142.654 [2] => 139.888 [3] => 154.228 [4] => 175.21
[5] => 195.342)我想让他变为array(188.869,142.654,139.888,154.288,175.21)
怎么改程序呢,多谢高手了。辛苦辛苦 展开
5个回答
展开全部
楼主真的是鸡蛋里挑骨头,array(188.869,142.654,139.888,154.288,175.21),打印出来就是
Array([0] => 188.869 [1] => 142.654 [2] => 139.888 [3] => 154.228 [4] => 175.21
[5] => 195.342)赛
Array([0] => 188.869 [1] => 142.654 [2] => 139.888 [3] => 154.228 [4] => 175.21
[5] => 195.342)赛
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
$sj =$row["sj"].",";
$dm000=$row["dm000"];
$ydata[] = $row[dm000];
}
$sj= substr( $sj,-1,1)
$dm000=$row["dm000"];
$ydata[] = $row[dm000];
}
$sj= substr( $sj,-1,1)
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
你是想改成一个array(188.869,142.654,139.888,154.288,175.21)这样的数组呢?还是想改成字符串呢?如果是数组的话,他的本身就是这种数组.如果想输出字符串的话.可以遍历数组,然后拼凑成这种格式. 也可以通过implode() 这个函数实现转换成字符串.然后首位添加需要的array和括号就行了!
来源:麦子学院
来源:麦子学院
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询