By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,751 Members | 1,216 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,751 IT Pros & Developers. It's quick & easy.

I'm having

P: n/a
Hi every one

I having problem using count() function
when I use count() the result came multiply 2

and this is my code :

////////////////////////////////////

$sql2 = "select * from user_previlag WHERE User_email= '$userEmail'";
$data2 = mysql_query($sql2);
$info = mysql_fetch_array($data2);

echo count($info);

\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
Sep 20 '08 #1
Share this Question
Share on Google+
2 Replies


P: n/a
*** sahm escribió/wrote (Sat, 20 Sep 2008 01:57:28 -0700 (PDT)):
I having problem using count() function
when I use count() the result came multiply 2

and this is my code :

////////////////////////////////////

$sql2 = "select * from user_previlag WHERE User_email= '$userEmail'";
$data2 = mysql_query($sql2);
$info = mysql_fetch_array($data2);

echo count($info);
From http://php.net/mysql_fetch_array:

array mysql_fetch_array ( resource $result [, int $result_type ] )

result_type: The type of array that is to be fetched. It's a constant and
can take the following values: MYSQL_ASSOC, MYSQL_NUM, and the default
value of MYSQL_BOTH.

Return Values: [...] The type of returned array depends on how result_type
is defined. By using MYSQL_BOTH (default), you'll get an array with both
associative and number indices.

So your problem has nothing to do with count(). Also, have a look at
http://php.net/print_r
--
-- http://alvaro.es - Álvaro G. Vicario - Burgos, Spain
-- Mi sitio sobre programación web: http://bits.demogracia.com
-- Mi web de humor en cubitos: http://www.demogracia.com
--
Sep 20 '08 #2

P: n/a
sahm <sa*****@gmail.comkirjoitti 20.09.2008:
>
I having problem using count() function
when I use count() the result came multiply 2

and this is my code :

////////////////////////////////////

$sql2 = "select * from user_previlag WHERE User_email= '$userEmail'";
$data2 = mysql_query($sql2);
$info = mysql_fetch_array($data2);

echo count($info);

\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
You should be using mysql_num_rows() function.

If you do print_r($info), you'll see why count() does that.

Sep 20 '08 #3

This discussion thread is closed

Replies have been disabled for this discussion.