Lassie Posted December 20, 2011 Share Posted December 20, 2011 I have a simple query and need to print the result. My code does not print a resulr but the query is valid and returns a result. Any help appreciated. $query = ("SELECT * FROM wp_book WHERE Author_ID = '$Author_ID'"); $result = mysql_query($query) or trigger_error("Query: $query\n<br />MySQL Error: " . mysql_error()); echo mysql_error(); if (!$result) { echo "<br />"; echo"No Result"; } echo"Result"; while($row = mysql_fetch_assoc($result)){ echo $row['WorkingTitle']; } Quote Link to comment https://forums.phpfreaks.com/topic/253559-problem-retrieving-data/ Share on other sites More sharing options...
Pikachu2000 Posted December 20, 2011 Share Posted December 20, 2011 How are you sure the query isn't returning an empty results set? Quote Link to comment https://forums.phpfreaks.com/topic/253559-problem-retrieving-data/#findComment-1299807 Share on other sites More sharing options...
Lassie Posted December 20, 2011 Author Share Posted December 20, 2011 Hi Thanks, Well I put the !$result in to check just that and the db does hol data for this query. ? Quote Link to comment https://forums.phpfreaks.com/topic/253559-problem-retrieving-data/#findComment-1299868 Share on other sites More sharing options...
Pikachu2000 Posted December 20, 2011 Share Posted December 20, 2011 That will determine if the query fails with an error. An empty result set is not a query failure, it's simply an empty results set. To determine if the query returns any results, you'd need to use mysql_num_rows. Quote Link to comment https://forums.phpfreaks.com/topic/253559-problem-retrieving-data/#findComment-1299897 Share on other sites More sharing options...
shankarganesh Posted December 21, 2011 Share Posted December 21, 2011 Hi, Please try it with this updated query, $query = ("SELECT * FROM wp_book WHERE Author_ID = '".$Author_ID.'""); Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/253559-problem-retrieving-data/#findComment-1300036 Share on other sites More sharing options...
dzelenika Posted December 21, 2011 Share Posted December 21, 2011 and of course remove parenthesis from code: $query = ("SELECT * FROM wp_book WHERE Author_ID = '".$Author_ID.'""); Quote Link to comment https://forums.phpfreaks.com/topic/253559-problem-retrieving-data/#findComment-1300038 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.