A JM Posted August 13, 2009 Share Posted August 13, 2009 I'm working on building a query page for my site which will allow users to select from drop downs what items to query the database on. I've created my result page with pagination, fields and filed names. The question that I have is when the user loads the page it runs a default query that then populates the page page - how can I set up my page to have an empty result that won't error with mySQL? Do I have to create my query options page as a separate page and then show the result page on the submit? Thanks for any ideas and suggestions. A JM, Quote Link to comment https://forums.phpfreaks.com/topic/170141-solved-how-to-setup-query-page-with-empty-result/ Share on other sites More sharing options...
p2grace Posted August 13, 2009 Share Posted August 13, 2009 Not sure exactly how your code structure is setup. If you query fields are determined from the $_GET vars, you can execute different queries based on whether or not those $_GET vars exist. However, if the fields being queried don't actually change, then more then likely your query itself isn't producing the error, but rather it's trying to retrieve the results of a query that has no rows (which produces the error). Solution for scenario 2: check if the query returned any rows before grabbing rows if(mysql_num_rows($query) == 0){ return ""; } Make sense? If you need more details you'll need to post some code so we can see the issue. Quote Link to comment https://forums.phpfreaks.com/topic/170141-solved-how-to-setup-query-page-with-empty-result/#findComment-897594 Share on other sites More sharing options...
A JM Posted August 13, 2009 Author Share Posted August 13, 2009 Makes some sense to just trap the error, thanks. So even though the query produces no results would that still generate the page, just without data? I guess I'm setting this up incorrectly as I'm showing the user the result page of a query that hasn't been run - so it probalby makes more sense to create a page with just the criteria and then create the result page. A JM, Quote Link to comment https://forums.phpfreaks.com/topic/170141-solved-how-to-setup-query-page-with-empty-result/#findComment-897604 Share on other sites More sharing options...
p2grace Posted August 13, 2009 Share Posted August 13, 2009 You can do it all within the same page, either way it works. If you don't want the query to execute without the $_GET vars, check to see if they exist before executing. if(isset($_GET['var'])){ $query = "..."; } Quote Link to comment https://forums.phpfreaks.com/topic/170141-solved-how-to-setup-query-page-with-empty-result/#findComment-897608 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.