0

Possible Duplicate:
How do i “echo” a “Resource id #6” from a MySql response in PHP?

I created a SELECT query but it has an error. When I print_r(result) I get the resource id#9 notice here is the code:

$query= "SELECT * FROM {$hotel_name} WHERE Bdate BETWEEN {$chack_in} AND {$chack_out}";

$availability = mysql_query($query);

confirm_query($availability);

print_r($availability);
Community
  • 1
  • 1
user605505
  • 59
  • 1
  • 3
  • 18
  • 2
    user605505, it took me about three months to learn that #9 was not code for which error occurred. It's a lack of a usable result from your query. And surprisingly so few places tell you this! Just thought I'd point that out. – Bryan Apr 02 '11 at 15:17
  • what is `confirm_query`? I am not familiar with it, and didnt find anything when i searched PHP manual – jon_darkstar Apr 02 '11 at 15:38

2 Answers2

5

'$availability` prints as 'resource id#9' because it is a resource. http://php.net/manual/en/language.types.resource.php

There is nothing wrong with this, it is expected. mysql_query returns resource types when the query executes successful, and false when it fails. You can call mysql_fetch_*($resource) on that resource to get data from it.

(Where * is assoc, object, array, etc)

jon_darkstar
  • 16,398
  • 7
  • 29
  • 37
0

$availability is the handle to the results, the fact it says #9 would imply it worked. You then need to loop through getting the results from $availability.

BugFinder
  • 17,474
  • 4
  • 36
  • 51
  • $availability_per_date= mysql_fetch_assoc($availability) print_r($availability_per_date); //gives me nothing i'm using before it mysql_num_fields which gives me the num of fields could it be the intenal pointer that i should reset? – user605505 Apr 02 '11 at 15:14
  • As above, using mysql_fetch_array or mysql_fetch_assoc etc, will return the rows. If you take a look at http://php.net/manual/en/function.mysql-fetch-assoc.php it has a good number of examples. The PHP manual is incredibly good at examples – BugFinder Apr 02 '11 at 16:01