Lassie Posted September 2, 2008 Share Posted September 2, 2008 I have a function to retireve books in a category selection. The function returns an array of books. I also want to return the number of books in the category so I can go on and paginate the results. How can I include the variable $num_books with the return result? function get_books($cat_id) { // query database for the books in a category if (!$cat_id || $cat_id=='') return false; $query = "select * from products where cat_id='$cat_id'"; $result = mysql_query($query); if (!$result) return false; $num_books = mysql_num_rows($result); if ($num_books ==0) return false; $result = db_result_to_array($result); return $result; } Quote Link to comment https://forums.phpfreaks.com/topic/122373-modify-function-to-return-2-results/ Share on other sites More sharing options...
Zane Posted September 2, 2008 Share Posted September 2, 2008 your best bet is to populate an array of all the stuff you want and return that because a multiple return is unheard of Quote Link to comment https://forums.phpfreaks.com/topic/122373-modify-function-to-return-2-results/#findComment-631859 Share on other sites More sharing options...
Lassie Posted September 2, 2008 Author Share Posted September 2, 2008 Right. How can I count the records in an array? Quote Link to comment https://forums.phpfreaks.com/topic/122373-modify-function-to-return-2-results/#findComment-631866 Share on other sites More sharing options...
Zane Posted September 2, 2008 Share Posted September 2, 2008 with the PHP count function http://php.net/count Quote Link to comment https://forums.phpfreaks.com/topic/122373-modify-function-to-return-2-results/#findComment-631871 Share on other sites More sharing options...
Lassie Posted September 2, 2008 Author Share Posted September 2, 2008 Many thanks. Quote Link to comment https://forums.phpfreaks.com/topic/122373-modify-function-to-return-2-results/#findComment-631882 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.