Why do I get “Resource id #4” when I apply print_r() to an array in PHP? [duplicate]

You are trying to print a mysql resource variable instead of the values contained within the resource it references. You must first try to extract the values you have gotten by using a function such as mysql_fetch_assoc().

You might also try mysql_fetch_array() or mysql_fetch_row(), but I find associative arrays quite nice as they allow you to access their values by the field name as in Mike’s example.

Leave a Comment