检查空白数组有什么问题?

时间:2013-10-30 10:34:47

标签: php mysql sql arrays

我有如下查询:

$sql = "SELECT * FROM member_details WHERE blood_group = 'O+'";

如果我将在phpmyadmin中执行此查询,那么我将获得零行。 但是当我回应阵列时,我就像是在追随。

$n = new data();

$res = $n -> querySend($sql);

$abc = mysql_fetch_array($res); 

//if i do like this
   echo $res;  // output getting as Resource id#6

//if i do like this then
   echo count($abc); // output getting as 1

//if i do like this then
   print_r($abc); die; // output getting as blank

我想检查$abc是否为空。 但由于上述输出,我无法检查它。 任何人都可以告诉我这个问题是什么。 提前谢谢。

3 个答案:

答案 0 :(得分:0)

您可以使用

进行检查
 if(empty($abc))

答案 1 :(得分:0)

您可以查看is_array(),例如:

if( is_array($abc) ) {
   echo "It is array";
}

顺便说一下,你应该这样做

if( mysql_num_rows($res) > 0 ) {
    $abc = mysql_fetch_array($res);    
}

答案 2 :(得分:0)

我建议从mysql_ *切换到mysqli_ *或PDO,不推荐使用Mysql_ *,并且在将来的php版本中无法使用。

在这种情况下你可以做的是,在获取数组之前检查结果的num_rows:
http://us1.php.net/mysql_num_rows(我知道,mysql_ *函数,但页面上有警告!)。