doz59484 2013-09-27 17:58
浏览 55

回显PHP数组不返回结果

So, guys, my problem is that i'm creating an array from a mysql column, but, when i echo the array items, it returns me nothing, i'm about this for a while and i'm not seeing a possible error, hope can get some help. Here' s my code: (I know about the mysql to mysqli, but i'm just beginning and trying the logical stuff. :))

$duracao = mysql_query(
    "SELECT SUM(fim_periodo-inicio_periodo)/0.01666667 AS mysum
 FROM afunda_eleva_$a"
); //THIS $duracao IS INSIDE A FOR LOOP THAT EXECUTES THE QUERY IF A CONDITION IS SATISFIED (DEPENDING ON $a and $prevNum), it is working fine!

while ($row2 = mysql_fetch_assoc($duracao))
{
    $duracao_afunda_eleva[] = $row2['mysum'];
}

so, to test some possible problems, i've put:

$i2 = sizeof($duracao_afunda_eleva);    
echo $i2;
echo <br>;

which returns me the right size of the array, the problem comes here, i think:

for($i1 = 0 ; $i1 < sizeof($duracao_afunda_eleva); $i1++)    
{
    echo $duracao_afunda_eleva[$i1] or die("couldn't echo"
    . mysql_error());        
    echo "<br>";    
}

and this returns me no value. I really would appreciate any suggestion. Thanks in advance!

  • 写回答

6条回答 默认 最新

  • dou2347 2013-09-27 18:02
    关注

    Try print_r instead of echo - echo outputs (string)$variable, which in case of an array is just "array". Also, echo is a language construct and not a function, so your or die(...) is problematic, as language constructs don't have return values.

    Generally it's better to not use or die(...) constructs, and handle problems correctly (using a defined return value, so cleanup code can run, for example). Also, not being able to output anything with echo would mean that your php/whatever installation is seriously gone bad, at which point you probably won't even reach that line in your code, and even then it won't have anything to do with mysql.

    评论

报告相同问题?

悬赏问题

  • ¥15 AT89C51控制8位八段数码管显示时钟。
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口