调用查询:注意:数组转换为字符串

时间:2016-04-20 01:30:02

标签: php mysql

我是一个尝试制作自己的网络应用的新手。我遇到了问题。我试图使用此代码从表中调用查询来查找等级

$rank="SELECT student_code, led2dt4engavgfinal, FIND_IN_SET(
    led2dt4engavgfinal,
    (SELECT GROUP_CONCAT(DISTINCT led2dt4engavgfinal ORDER BY led2dt4engavgfinal DESC)
    FROM led2deng)
) as rank
FROM led2deng;"; 
$myQry2 = mysql_query($rank, $koneksidb)  or die ("Query salah : ".mysql_error());
$myData2 = mysql_fetch_array($myQry2);

我用 此代码调用数据

<?php echo $myData2; ?>

但它出来了

  

注意:......中的数组转换为字符串

我该如何解决这个问题?

1 个答案:

答案 0 :(得分:0)

像这样迭代结果数组:

foreach($myData2 as $row){

  //Now access columns like this
  echo $row["student_code"];
  echo $row["led2dt4engavgfinal"];

}

更新:试试这个

<?php 
$rank="SELECT student_code, led2dt4engavgfinal, FIND_IN_SET( led2dt4engavgfinal , (SELECT GROUP_CONCAT( DISTINCT led2dt4engavgfinal ORDER BY led2dt4engavgfinal DESC ) FROM led2deng) ) as rank FROM led2deng;"; 
$myQry2 = mysql_query($rank, $koneksidb) or die ("Query salah : ".mysql_error()); 
$myData2 = mysql_fetch_array($myQry2); 

foreach($myData2 as $row) {
    echo $row['student_code'];
    echo $row['led2dt4engavgfinal'];
    echo $row['rank'];
}

&GT;