...

View Full Version : Resource Id #4 error



nani_nisha06
10-22-2012, 03:46 PM
Hi All,

I am not sure why this is bugging me from long time today.

in the below case I am trying to call the integer which is stored in the DB using the select command but still it say resource Id #4.



$sql1="SELECT 'ip' FROM $tbl_name WHERE ip='$IP2'";
$result1= mysql_query($sql1) or die(mysql_error());
echo $result1;
exit;


any once can help me.

I suspect issue with the mysql_query() fucntion can one suggest, i have also tried using other functions by object, row, array and still i don't see any positive sign.

Fou-Lu
10-22-2012, 04:03 PM
You cannot print the result of a resource. PHP hasn't a clue how to deal with it, so you need to pass it to a method that can such as mysql_fetch_assoc.
That will only return the literal text 'ip' though. Perhaps that should be without the quotes if that's the name of a field.

nani_nisha06
10-22-2012, 04:13 PM
You cannot print the result of a resource. PHP hasn't a clue how to deal with it, so you need to pass it to a method that can such as mysql_fetch_assoc.
That will only return the literal text 'ip' though. Perhaps that should be without the quotes if that's the name of a field.

but when I am trying to do mysql_fetch_assoc, it gives me below error.


Warning: mysql_fetch_assoc() expects parameter 1 to be resource, string given in C:\xampp\htdocs\FINALMYM\checklogin.php on line 22

Fou-Lu
10-22-2012, 04:14 PM
What are you passing to mysql_fetch_assoc? This error would indicate with the above block you are giving it $sql1, not $result1.

nani_nisha06
10-22-2012, 06:02 PM
What are you passing to mysql_fetch_assoc? This error would indicate with the above block you are giving it $sql1, not $result1.

Fou-lu,

in sql1 i am trying to use the select command where in to call a integer value from database.

at $result1 i am trying to mysql_fetch_assoc.

Please help me !!!!

Fou-Lu
10-22-2012, 06:36 PM
Fou-lu,

in sql1 i am trying to use the select command where in to call a integer value from database.

at $result1 i am trying to mysql_fetch_assoc.

Please help me !!!!

I don't follow you on this one.
Post the code you have so I can see what you are doing with the resource.

nani_nisha06
10-22-2012, 06:55 PM
I don't follow you on this one.
Post the code you have so I can see what you are doing with the resource.


$sql1="SELECT ip FROM $tbl_name WHERE ip='$IP2'";
$result1= mysql_query($sql1);
$info = mysql_fetch_array($result1);

My Database as this value and i want to call this using PHP???
ip
168039683
168431123
168431245

Fou-Lu
10-22-2012, 07:16 PM
This is correct, although if ip is an integer it shouldn't be quoted in the where clause. MySQL by default will accept a loose datatype though.
$info will contain an offset called 'ip' within it. That will represent the first record of the matching query. If you need more, shove it in a while loop to evaluate until it hits false.

nani_nisha06
10-23-2012, 07:51 AM
This is correct, although if ip is an integer it shouldn't be quoted in the where clause. MySQL by default will accept a loose datatype though.
$info will contain an offset called 'ip' within it. That will represent the first record of the matching query. If you need more, shove it in a while loop to evaluate until it hits false.

the above procedure you said showing correct but when echoed $info it returns as "array" alone I don't now why ?

On the while loop I am not sure i need to check for it....

Fou-Lu
10-23-2012, 02:27 PM
You cannot print an array. You can print_r an array for information. You need to access an offset within an array.
Check the examples here for the use of mysql_fetch_* in an loop: http://ca2.php.net/manual/en/function.mysql-fetch-array.php

nani_nisha06
10-23-2012, 04:15 PM
You cannot print an array. You can print_r an array for information. You need to access an offset within an array.
Check the examples here for the use of mysql_fetch_* in an loop: http://ca2.php.net/manual/en/function.mysql-fetch-array.php

fou-lu,

I have already solved this issue using the same as you mention above.

Regards,
nani



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum