Possible Duplicate:
mysql_fetch_array() expects parameter 1 to be resource, boolean given in select
What is the cause of error in my code and how I can to fix?(i use of codeigniter)
$开发者_如何学Cquery_hotel_search = $this->db->query("SELECT * FROM hotel_submits WHERE name LIKE '%$hotel_search%' ORDER BY name asc");
$units = array();
while( $row = mysql_fetch_row( $query_hotel_search ) ) // Line 27
{
$units = unserialize( $row[0] );
}
echo json_encode(var_dump($units));
Error:
A PHP Error was encountered
Severity: Warning Message: mysql_fetch_row() expects parameter 1 to be resource, object given Line Number: 27
Output: array(0) { } null
UPDATE:
Error:
A PHP Error was encountered
Severity: Notice Message: unserialize() [function.unserialize]: Error at offset 0 of 3 bytes Line Number: 29
Output: bool(false) null
See my database: http://i.stack.imgur.com/IORSM.jpg
$query_hotel_search = mysql_query("SELECT * FROM hotel_submits WHERE name LIKE '%$hotel_search%' ORDER BY name asc");
if(mysql_num_rows($query_hotel_search)==0){
return '0';
}else{
$units = array();
while( $row = mysql_fetch_row( $query_hotel_search ) )
{
$units = unserialize( $row->units[0] ); // Line 29
}
echo json_encode(var_dump($units));
}
http://de2.php.net/manual/en/function.mysql-fetch-row.php
mysql_fetch_row() takes not the query itself but rather the result from the mysql_query command (which is a resource).
Look at the example at the PHP Documentation (linked at the top) and you will get the functionality of mysql_fetch_row.
Maybe the assignment of $query_hotel_search can clarify the situation.
You are using a codeigniter object as mysql resource. Instead you should use object iterator provided by codeigniter to loop through the results.
foreach($query_hotel_search->result() as $row)
{
// $row as object
}
foreach($query_hotel_search->result_array() as $row)
{
// $row as array
}
For the second part (UPDATE), mysql_fetch_row() return an enumerated array. so you should use:
$units = unserialize($row[12]);
精彩评论