Page 1 of 1

Resource ID #2?

Posted: Sun Oct 20, 2002 7:01 pm
by Tom
Hey,
I'm trying to search a MySQL table, but the only output i get is Resource ID #2. I have no idea what this is and why it's there, so I'm here to ask you guys. Here's the line that searches the table "userinfo" in the db "users" (Yes, the database has been specified).

Code: Select all

$result = mysql_query("SELECT * FROM userinfo WHERE name LIKE '$search'");
I have 2 names in the database (I'm just now learning MySQL so it's basically a test database), both of which i am absolutely positive are there.

Now here's my problem. When i search for one name, I get the output of "Resource ID #2". When i search for the other, I get absolutely nothing.

I'm using Php 4.0.6, Apache 1.3.20, and MySQL 3.23.51 if that matters at all.

Take it easy, - Tom.

Posted: Sun Oct 20, 2002 7:25 pm
by qads
mysq_query does't get the data out, it just finds out if the data can be pulled out or not.

you need to use

$$result2 = mysql_fetch_array($result);

then you can print that out like:

echo $result2[fieldname];

you can also use mysql_fetch_row($result);
read more at http://www.mysql.com

Posted: Sun Oct 20, 2002 10:49 pm
by hob_goblin
1) if you're just grabbing one row, call it like:

$query = mysql_query("...");
$data = mysql_fetch_assoc($query);
echo $data['column'];

2) if you're doing alot of rows...

$query = mysql_query("SELECT * FROM table");
while($data = mysql_fetch_assoc($query)){
echo $data['column'];
}

Posted: Mon Oct 21, 2002 6:13 am
by Takuma
According to the old post mysql_fetch_assoc() is actually slower than mysql_fetch_array() (only by tiny bit...). I would use mysql_fetch_array() if you want to put the result into an object use mysql_fetch_object().

Posted: Mon Oct 21, 2002 6:18 am
by twigletmac
From the manual:
An important thing to note is that using mysql_fetch_assoc() is not significantly slower than using mysql_fetch_row(), while it provides a significant added value.
and
An important thing to note is that using mysql_fetch_array() is not significantly slower than using mysql_fetch_row(), while it provides a significant added value.
I don't see any reason why mysql_fetch_array() would be faster than mysql_fetch_assoc().

Mac

Posted: Mon Oct 21, 2002 12:50 pm
by Takuma
Mmmm, I thought in the old post, it said mysql_fetch_array() is a bit faster than mysql_fetch_assoc()

Posted: Mon Oct 21, 2002 12:52 pm
by twigletmac
Old post?

Mac