Jump to content

[SOLVED] How to setup query page with empty result?


Recommended Posts

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,

 

 

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.

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,

 

 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.