Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 11 of 11
  1. #1
    Regular Coder
    Join Date
    Oct 2012
    Location
    mother land --india
    Posts
    164
    Thanks
    38
    Thanked 2 Times in 2 Posts

    Resource Id #4 error

    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.

    Code:
    $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.

  • #2
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,987
    Thanks
    4
    Thanked 2,660 Times in 2,629 Posts
    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.

  • #3
    Regular Coder
    Join Date
    Oct 2012
    Location
    mother land --india
    Posts
    164
    Thanks
    38
    Thanked 2 Times in 2 Posts
    Quote Originally Posted by Fou-Lu View Post
    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.

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

  • #4
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,987
    Thanks
    4
    Thanked 2,660 Times in 2,629 Posts
    What are you passing to mysql_fetch_assoc? This error would indicate with the above block you are giving it $sql1, not $result1.

  • #5
    Regular Coder
    Join Date
    Oct 2012
    Location
    mother land --india
    Posts
    164
    Thanks
    38
    Thanked 2 Times in 2 Posts
    Quote Originally Posted by Fou-Lu View Post
    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 !!!!

  • #6
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,987
    Thanks
    4
    Thanked 2,660 Times in 2,629 Posts
    Quote Originally Posted by nani_nisha06 View Post
    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.

  • #7
    Regular Coder
    Join Date
    Oct 2012
    Location
    mother land --india
    Posts
    164
    Thanks
    38
    Thanked 2 Times in 2 Posts
    Quote Originally Posted by Fou-Lu View Post
    I don't follow you on this one.
    Post the code you have so I can see what you are doing with the resource.
    Code:
    $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

  • #8
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,987
    Thanks
    4
    Thanked 2,660 Times in 2,629 Posts
    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.

  • #9
    Regular Coder
    Join Date
    Oct 2012
    Location
    mother land --india
    Posts
    164
    Thanks
    38
    Thanked 2 Times in 2 Posts
    Quote Originally Posted by Fou-Lu View Post
    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....

  • #10
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,987
    Thanks
    4
    Thanked 2,660 Times in 2,629 Posts
    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/functio...etch-array.php

  • #11
    Regular Coder
    Join Date
    Oct 2012
    Location
    mother land --india
    Posts
    164
    Thanks
    38
    Thanked 2 Times in 2 Posts
    Quote Originally Posted by Fou-Lu View Post
    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/functio...etch-array.php
    fou-lu,

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

    Regards,
    nani


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •