1

I'm calling a Procedure from the PHP form, which the user inputs an Address or Postcode to search on in order to return details around the customer.

My issue is that within my WHERE clause I've set the fields to search LIKE the input, but when I open my search form it returns all rows from the table, when this WHERE clause below is used.

WHERE (AddressLine1 LIKE CONCAT('%', street_name, '%')) OR (Postcode LIKE CONCAT('%', post_code, '%'))

If I changed it and the user put the specific Postcode or Address like below,

WHERE ((Postcode = post_code OR street_name IS NULL)
            OR (AddressLine1 = street_name OR post_code IS NULL))

then the search page would return no rows of data until the query had run. How can I stop the query from showing all rows in the table until the query has run?

5
  • What do you mean by 'until the query had run'? Of course there are no results if you don't run the query. Commented Nov 9, 2014 at 21:24
  • When I open my php page that the search form is on, the table where I show the results is empty on using the 2nd example, but on the first example the table shows all records Commented Nov 9, 2014 at 21:28
  • I'm just calling the Procedures as follows from the search page CALL sp_jobsearch('".$searchpostcode."', '".$searchaddress."'); Commented Nov 9, 2014 at 21:29
  • So the second version is exactly what you are looking for? I don't see the problem. Please specify the desired behavior in your question more clearly. Commented Nov 9, 2014 at 21:33
  • No, I want to use the 1st option, be able to use LIKE in the WHERE clause, but not show all results in the table when the page loads. If I have thousands of records in the table then this would show when the page opens, but I dont want this, I want an empty table until the input of either Address or Postcode is input in the search boxes Commented Nov 9, 2014 at 21:34

1 Answer 1

1

Instead of modifying the SQL query, you should check whether to execute the query or not in the PHP code.

For example, you could use this condition to check if both parameters where specified:

if (!empty($searchpostcode) && $searchaddress) {
    sp_jobsearch('".$searchpostcode."', '".$searchaddress."');
}

However, I'm fairly certain that you could directly decide whether you are showing the input form or the query result page.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.