johnmerlino Posted August 30, 2010 Share Posted August 30, 2010 Hey all, The mysql_query function is failing in the show function and I'm not sure why: function index($item){ db_connect(); $query = "SELECT * FROM $item ORDER BY $item.id DESC"; $result = mysql_query($query); $result = db_result_to_array($result); return $result; } function show($item, $id){ db_connect(); $query = sprintf("SELECT * FROM $item WHERE $item.id = '%s", mysql_real_escape_string($id)); $result = mysql_query($query); $row = mysql_fetch_array($result); return $row; } //Stuff that belongs in view $books = index('books'); foreach($books as $book){ echo $book['title'].'</ br>'; } $book = show('books', 1); echo $book['title'].'</ br>'; Thanks for any response. Link to comment https://forums.phpfreaks.com/topic/212075-warning-mysql_fetch_array-expects-parameter-1-to-be-resource-boolean-given/ Share on other sites More sharing options...
johnmerlino Posted August 30, 2010 Author Share Posted August 30, 2010 Here is the parameter I am passing into the show function: $book = show('books', 1); echo $book['title'].'</ br>'; Link to comment https://forums.phpfreaks.com/topic/212075-warning-mysql_fetch_array-expects-parameter-1-to-be-resource-boolean-given/#findComment-1105214 Share on other sites More sharing options...
wildteen88 Posted August 30, 2010 Share Posted August 30, 2010 This error usually occurs due to one of the following You're not connected to the database The query returned no results as there is no records with the id of 1 Or your query failed due to an error. To see if their is an error use the function mysql_error, eg $result = mysql_query($query) or trigger_error('MySQL Error: ' . mysql_error() . '<br />Query: ' . $query, E_USER_ERROR ); Link to comment https://forums.phpfreaks.com/topic/212075-warning-mysql_fetch_array-expects-parameter-1-to-be-resource-boolean-given/#findComment-1105216 Share on other sites More sharing options...
johnmerlino Posted August 30, 2010 Author Share Posted August 30, 2010 The mysql_error() made it obvious that I was missing quotes around %s. Thanks. Link to comment https://forums.phpfreaks.com/topic/212075-warning-mysql_fetch_array-expects-parameter-1-to-be-resource-boolean-given/#findComment-1105231 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.