Resource ID #2?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Tom
Forum Newbie
Posts: 20
Joined: Sat Oct 05, 2002 5:24 pm
Location: Southwest FL

Resource ID #2?

Post 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.
qads
DevNet Resident
Posts: 1199
Joined: Tue Apr 23, 2002 10:02 am
Location: Brisbane

Post 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
User avatar
hob_goblin
Forum Regular
Posts: 978
Joined: Sun Apr 28, 2002 9:53 pm
Contact:

Post 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'];
}
User avatar
Takuma
Forum Regular
Posts: 931
Joined: Sun Aug 04, 2002 10:24 am
Location: UK
Contact:

Post 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().
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post 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
User avatar
Takuma
Forum Regular
Posts: 931
Joined: Sun Aug 04, 2002 10:24 am
Location: UK
Contact:

Post by Takuma »

Mmmm, I thought in the old post, it said mysql_fetch_array() is a bit faster than mysql_fetch_assoc()
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

Old post?

Mac
Post Reply