-1

I am trying to select multiple data rows from the database like this:

$db = mysql_connect("example.example.com","username","password");
mysql_select_db("database", $db);

$data = mysql_query("SELECT * FROM users WHERE activated = 1", $db)
    or die("Problems with database: ".mysql_error($db));
$row = mysql_fetch_array($data);

but it gives me this error:

mysql_fetch_array() expects parameter 1 to be resource

although when I do var_dump($data); it tells me that it is resource(6) of type (mysql result).

I have tried various workarounds but none of them have worked. Could anyone tell me what's wrong?

Thanks in advance.

jumbot
  • 789
  • 5
  • 23
  • 2
    `var_dump($data)` - debug what you're trying to work with. – deceze Apr 07 '14 at 09:09
  • @deceze I have done this and I get `resource(6) of type (mysql result)`. I can't see what's wrong. – jumbot Apr 07 '14 at 09:19
  • Is this verbatim your code? There's absolutely *nothing* between the `mysql_query` and `mysql_fetch_array` line? – deceze Apr 07 '14 at 09:23
  • @deceze Nothing at all, apart from from `var_dump($data)` (see edit) – jumbot Apr 07 '14 at 09:25
  • Then it should be impossible for this particular code to throw this particular error. There's nothing else...? A loop? A function call? The error originates from somewhere else entirely? – deceze Apr 07 '14 at 09:27
  • I am trying to select **multiple** rows from the database. Could it have something to do with that? – jumbot Apr 07 '14 at 09:34
  • Nope, that's quite irrelevant. – deceze Apr 07 '14 at 09:43
  • I have found a workaround that works. Turns out there was some problem with multiple rows and the way I was treating them. Sorry about that. – jumbot Apr 07 '14 at 10:05

1 Answers1

-1

Please try fillowing code.

$data = mysql_query("SELECT * FROM users WHERE activated = 1")
    or die("Problems with database: ".mysql_error($db));
$row = mysql_fetch_array($data);
Sushant
  • 123
  • 4