mysql_fetch_array返回一个数组,数字为“1”
I have a problem with mysql_fetch_array. I'm trying to do this:
我有mysql_fetch_array的问题。我正在尝试这样做:
if(count(mysql_fetch_array(mysql_query($peticion)))) {
array_push($errores, $texto['conta_existe']);
}
The previous code should detect if mysql_fetch_array found a row in my database and, if it found at least one, an array should be pushed. Problem is that if I haven't got anything in my db, fetch_array returns the number "1".
前面的代码应检测mysql_fetch_array是否在我的数据库中找到了一行,如果找到至少一行,则应该推送一个数组。问题是,如果我的数据库中没有任何内容,则fetch_array返回数字“1”。
I tried to find what's happening with this peace of code:
我试图通过这种代码安静来发现正在发生的事情:
$arrayc = mysql_fetch_array(mysql_query($peticion), MYSQL_NUM);
echo 'PRINT_R: ';
echo print_r($arrayc);
echo '<br>COUNT: ';
echo count($arrayc);
And returns this:
并返回:
PRINT_R: Array ( [0] => FLEREX [conta] => FLEREX ) 1
PRINT_R:数组([0] => FLEREX [conta] => FLEREX)1
COUNT: 2
COUNT:2
I don't understand why there's that number one there, after the array. The previous quote was returned with only one row, to show you the array; but if there's not any row in the db, this is what I get:
我不明白为什么在阵列之后那里有第一号。之前的引用仅返回一行,以显示数组;但如果数据库中没有任何行,这就是我得到的:
PRINT_R: 1
PRINT_R:1
COUNT: 1
COUNT:1
I don't know where comes from that one, but is always there.
我不知道那个来自哪里,但总是在那里。
Thanks for reading and sorry for my bad english.
感谢您阅读并抱歉我的英语不好。
2 个解决方案
#1
1
Try mysql_num_rows instead of count and delete the mysql_fetch_array
尝试mysql_num_rows而不是count并删除mysql_fetch_array
更多相关文章
- 正则表达式匹配wordpress类似的短代码,用于自闭和封闭。
- PHP-从多维数组中删除重复值
- php文件显示代码在Chrome
- 怎么知道php代码运行时调用了那个类、那个方法呢?
- 更改数组键而不更改顺序
- 在PHP中更改关联数组索引的位置
- 如何在数组中存储产品数量
- php吧字符串直接转换成数组处理
- 使用 PHP usort() 通过用户自定义的比较函数对数组进行排序