size_of返回错误的答案 [英] size_of returning wrong answer

查看:76
本文介绍了size_of返回错误的答案的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用php从mysql表中获取一些数据.该表返回正确的结果,但是因为该表有很多列,我认为可以为此创建一个for循环并将所有值保存为val1val2等.我首先使用while循环是几行:

I am using php to get some data from mysql table. The table returns the right results however because the table has many columns, i thought that i could create a for loop for this and save all my values as val1, val2 etc. I am first using a while loop as there can be several rows:

while($row1 = mysql_fetch_array($sql2)){
    for($i = 1; $i < sizeof($row1); $i++) {
        $val.$i = $row1[$i];
    }

但是由于某种原因,sizeof($ row1)返回40,而我在该表中只有18列.

However for some reason sizeof($row1) returns 40 whereas i have only 18 columns in that table.

我认为$val.$i = $row1[$i];不是声明变量的正确方法吗?

I think $val.$i = $row1[$i]; is not the right way to declare a variable?

我知道我会犯一个愚蠢的错误,但是我无法弄清楚. :S

I know i would have made a silly mistake, but i am unable to figure it out. :S

推荐答案

您将要指定结果类型:

mysql_fetch_array($sql2, MYSQL_NUM);

手册:

通过使用MYSQL_BOTH(默认),您将获得一个包含两个数组 关联索引和数字索引.

By using MYSQL_BOTH (default), you'll get an array with both associative and number indices.

这篇关于size_of返回错误的答案的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆