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

更多相关文章

  1. 正则表达式匹配wordpress类似的短代码,用于自闭和封闭。
  2. PHP-从多维数组中删除重复值
  3. php文件显示代码在Chrome
  4. 怎么知道php代码运行时调用了那个类、那个方法呢?
  5. 更改数组键而不更改顺序
  6. 在PHP中更改关联数组索引的位置
  7. 如何在数组中存储产品数量
  8. php吧字符串直接转换成数组处理
  9. 使用 PHP usort() 通过用户自定义的比较函数对数组进行排序

随机推荐

  1. Android故障积累----(1/N)
  2. Android HandlerThread
  3. Android屏幕自适应详解
  4. 让应用程序不被任务管理器杀死...(获取系
  5. 2011.07.11(3)——— android xliff字符串
  6. android studio 中设置apk的版本号
  7. android 积累一些自定义view的知识
  8. 【Android】Android Studio启动配置gradl
  9. android 技术文章个人搜索集锦
  10. android实时监听网络状态并在断网的情况