• 0

Search Returning Results Empty


Question

I am having a tiny problem getting my search results for my properties. I can't seem to get any results when searching.

I have uploaded the search page to this post. If any one can have a look at this and correct any errors found.

This is the table structure for storing the properties in my database.

Properties

CREATE TABLE IF NOT EXISTS `properties` (
  `property_id` int(11) NOT NULL auto_increment,
  `username` varchar(20) collate utf8_bin NOT NULL,
  `date_entered` datetime NOT NULL default '0000-00-00 00:00:00',
  `status` varchar(20) collate utf8_bin NOT NULL default 'Draft',
  `sale_type` varchar(255) collate utf8_bin NOT NULL,
  `category` varchar(255) collate utf8_bin NOT NULL,
  `name` varchar(255) collate utf8_bin NOT NULL default '',
  `address` varchar(255) collate utf8_bin NOT NULL default '',
  `village` varchar(255) collate utf8_bin NOT NULL,
  `lng` float(10,6) NOT NULL,
  `lat` float(10,6) NOT NULL,
  `department` varchar(255) collate utf8_bin NOT NULL,
  `postcode` varchar(255) collate utf8_bin NOT NULL,
  `telephone` varchar(255) collate utf8_bin NOT NULL default '',
  `mobile` varchar(255) collate utf8_bin NOT NULL,
  `email` varchar(255) collate utf8_bin NOT NULL default '',
  `description_fr` text collate utf8_bin NOT NULL,
  `description_en` text collate utf8_bin NOT NULL,
  `price` varchar(255) collate utf8_bin NOT NULL,
  `price_change` varchar(255) collate utf8_bin NOT NULL default 'no',
  `bedrooms` char(1) collate utf8_bin NOT NULL default '0',
  `bathrooms` char(1) collate utf8_bin NOT NULL default '0',
  `view` varchar(255) collate utf8_bin NOT NULL default '',
  `meters` varchar(20) collate utf8_bin NOT NULL,
  `terrain` varchar(255) collate utf8_bin NOT NULL,
  `pool` varchar(3) collate utf8_bin NOT NULL default 'no',
  `garage` varchar(3) collate utf8_bin NOT NULL default 'no',
  `garage_size` varchar(11) collate utf8_bin NOT NULL default '',
  `front_garden` varchar(5) collate utf8_bin NOT NULL,
  `rear_garden` varchar(5) collate utf8_bin NOT NULL,
  `int_features` text collate utf8_bin NOT NULL,
  `ext_features` text collate utf8_bin NOT NULL,
  `video_tour` varchar(255) collate utf8_bin NOT NULL,
  `featured` char(3) collate utf8_bin NOT NULL default 'no',
  `fees` varchar(255) collate utf8_bin NOT NULL default '',
  `tax` varchar(255) collate utf8_bin NOT NULL default '',
  `photo1` varchar(255) collate utf8_bin NOT NULL default 'empty',
  `photo2` varchar(255) collate utf8_bin NOT NULL default 'empty',
  `photo3` varchar(255) collate utf8_bin NOT NULL default 'empty',
  `photo4` varchar(255) collate utf8_bin NOT NULL default 'empty',
  `photo5` varchar(255) collate utf8_bin NOT NULL default 'empty',
  `photo6` varchar(255) collate utf8_bin NOT NULL default 'empty',
  `photo7` varchar(255) collate utf8_bin NOT NULL default 'empty',
  `photo8` varchar(255) collate utf8_bin NOT NULL default 'empty',
  `photo9` varchar(255) collate utf8_bin NOT NULL default 'empty',
  `photo10` varchar(255) collate utf8_bin NOT NULL default 'empty',
  `photo11` varchar(255) collate utf8_bin NOT NULL default 'empty',
  `photo12` varchar(255) collate utf8_bin NOT NULL default 'empty',
  `visits` varchar(255) collate utf8_bin NOT NULL,
  `last_visit` datetime NOT NULL default '0000-00-00 00:00:00',
  `last_edit` datetime NOT NULL default '0000-00-00 00:00:00',
  `active` varchar(3) collate utf8_bin NOT NULL default 'no',
  PRIMARY KEY  (`property_id`),
  KEY `user_id` (`username`),
  FULLTEXT KEY `category` (`category`)
) ENGINE=MyISAM  DEFAULT CHARSET=utf8 COLLATE=utf8_bin COMMENT='This table stores the properties posted by the users.' AUTO_INCREMENT=1;

If any one can help me on this I would very much appreciate it.

Thank you.

search.phpFetching info...

Link to comment
https://www.neowin.net/forum/topic/655264-search-returning-results-empty/
Share on other sites

Recommended Posts

  • 0

I'm not even sure what some of your queries are supposed to do.

"SELECT meters FROM properties WHERE 1 AND 2 AND 3 AND 4 AND 5 AND 6 AND 7 AND 8 AND 9 AND 10 AND 11 AND 12 AND 13 AND 14 AND 15 AND 16 AND 17 AND 18 AND 19 AND 20 AND 21 AND 22 AND 23 AND 24 AND 25 AND 26 AND 27 AND 28 AND 29 AND 30"

What are you trying to do with that?

Can't really help you clean your PHP code if I don't know what you're trying to do.

You're also performing queries and not doing anything with the data that's returned.

In regards to your database, I'd start by normalising it to at least First Normal Form. This is what RDBMSes were designed for.

For example, get rid of "photo x" fields and put them in their own table. Perhaps even splitting the descriptions into another table.

Also, setting the bedrooms/bathrooms to an INT would allow for searching for "at least y" bathrooms/bedrooms.

The values where you're expecting a yes/no answer, use a boolean type, MySQL will use INT(1).

  • 0

The problem seems to be you're using AND for the query:

....AND address LIKE '%%$keyword%%' AND village LIKE '%%$keyword%%' AND postcode LIKE '%%$keyword%%' AND price LIKE '%%$keyword%%'.....

Unlikely that any keyword will be in the address, village, postcode and price all at the same time.

Also, 3 other things:

Run any value through mysql_real_escape_string before letting it into a query, use:

if isset($_POST['keyword']) {
....
//do query, etc
....
}

otherwise it will run an empty query each time and normalize that database.

  • 0
  zer0day said:
The problem seems to be you're using AND for the query:

....AND address LIKE '%%$keyword%%' AND village LIKE '%%$keyword%%' AND postcode LIKE '%%$keyword%%' AND price LIKE '%%$keyword%%'.....

Unlikely that any keyword will be in the address, village, postcode and price all at the same time.

Also, 3 other things:

Run any value through mysql_real_escape_string before letting it into a query, use:

if isset($_POST['keyword']) {
....
//do query, etc
....
}

otherwise it will run an empty query each time and normalize that database.

Ok I just relised that I was writing a function that was supposed to be for another page so we will push that a side for the moment. I have now uploaded the correct search.php page.

I am receving these errors when the page loads.

Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/account/public_html/search.php on line 61

Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in /home/account/public_html/search.php on line 62

properties found:
Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in /home/account/public_html/search.php on line 270

Error, query failed

If any one can help on fixing this one first with me that would be great.

search.phpFetching info...

  • 0

Line 59:

$querySearch = "SELECT * FROM properties WHERE status='Published' AND active='yes' AND category LIKE '%".$_POST['category']."%' $VILLAGEVAR $DEPARTMENTVAR $PRICEVAR $PRICECHANGEVAR $BEDROOMSVAR $BATHROOMSVAR $SALETYPEVAR  ORDER BY `property_id` DESC limit $offset, $limit";

".$_POST['category']."% <-- You have used a " in the middle of the query, which will cause it to fail.

  • 0

Change line 60 to

$resultListings = mysql_query($querySearch) or die(mysql_error());

Hopefully this will return the MySQL error message.

Also, your script is open to SQL injection attack, replace lines 13-22 with

$citeria_pricetype = mysql_real_escape_string($_POST['sale_type']);
//....
// etc.
$citeria_meters = mysql_real_escape_string($_POST['meters']);
//etc

  • 0
  zer0day said:
Change line 60 to

$resultListings = mysql_query($querySearch) or die(mysql_error());

Hopefully this will return the MySQL error message.

Also, your script is open to SQL injection attack, replace lines 13-22 with

$citeria_pricetype = mysql_real_escape_string($_POST['sale_type']);
//....
// etc.
$citeria_meters = mysql_real_escape_string($_POST['meters']);
//etc

OK I made your changes zer0day but now I get this error.

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1

I have attached the latest version of the page.

search.phpFetching info...

  • 0

Something is broke with your sql query, most likely the variables aren't being replaced.

Add

echo $querySearch;

after line 49 to see what the query looks like.

Didn't notice this earlier, but some _POST variables are not being sanitized.

From lines 24-46, anywhere you use $POST['somevar'], change it to mysql_real_escape_string($_POST['somevar']);

  • 0
  zer0day said:
Something is broke with your sql query, most likely the variables aren't being replaced.

Add

echo $querySearch;

after line 49 to see what the query looks like.

Didn't notice this earlier, but some _POST variables are not being sanitized.

From lines 24-46, anywhere you use $POST['somevar'], change it to mysql_real_escape_string($_POST['somevar']);

OK I have made those changes you mentioned. I have uploaded the latest copy of my page. Please check the code to make sure I have put it where you asked me to place.

I get this error now instead.

Parse error: syntax error, unexpected T_STRING, expecting T_VARIABLE or '$' in /home/account/public_html/search.php on line 24

search.phpFetching info...

  • 0

I've attached a new file search.php which should fix the problem. I also changed the code so it only searches when the submit button is pressed. Hopefully it should work now.

Is there a link to see the site in action? To see what errors it spits out, etc.

search.phpFetching info...

  • 0
  zer0day said:
I've attached a new file search.php which should fix the problem. I also changed the code so it only searches when the submit button is pressed. Hopefully it should work now.

Is there a link to see the site in action? To see what errors it spits out, etc.

I have made a few more changes to the page, it's starting to work but still needs tweaking.

I have also echoed the pagenation query so that you can see what its doing.

If you can have a look at the code I have uploaded and if you would like to view the site to see how it works and what it looks like I have sent you a PM message with the login details.

search.phpFetching info...

  • 0
  admin2gd1 said:
I have made a few more changes to the page, it's starting to work but still needs tweaking.

I have also echoed the pagenation query so that you can see what its doing.

If you can have a look at the code I have uploaded and if you would like to view the site to see how it works and what it looks like I have sent you a PM message with the login details.

I have done a thorough test on my search page and these are the things that are not working. When searching for properties, the results say how many there are but don't display just those properties the user searched for.

When searching for bedrooms, bathrooms all i get is my echo displaying.

I do have this only error:-

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' ORDER BY `property_id` DESC limit 10' at line 1

When getting the number of results of how many properties found, it only goes up to ten because of how many properties I want to display per page.

All this is what needs correcting now.

I have uploaded the latest search.php page after making a few fixes from the last post.

search.phpFetching info...

  • 0

firstly, really important to you finding bugs, make sure you have that code i gave you previously to make sure all php errors and warnings are displayed.

you need to make sure you ALWAYS initialize variables. for example, $SALETYPEVAR does not exist unless the if statement that fills it in is true. with php v4 (and php 5 if register globals is turned on) this creates a serious security vulnerability! an attacker could place SALETYPEVAR=[attackstring] in the query string, and perform an sql injection. i've tried to correct this for you!

you were missing a single quote in two places when assembling your first query, i've fixed that along with a bunch of other tweaks.

in the middle of the script, you were using a variable to calculate the results offset. this variable was being filled with the contents of another variable that when no form was submitted, didn't exist, and when a form was submitted, contained an sql result set... i believe you simply needed to use the variable $limit in the calculation, so i've fixed that.

try this new copy:

search.phpFetching info...

  • 0
  theblazingangel said:
firstly, really important to you finding bugs, make sure you have that code i gave you previously to make sure all php errors and warnings are displayed.

you need to make sure you ALWAYS initialize variables. for example, $SALETYPEVAR does not exist unless the if statement that fills it in is true. with php v4 (and php 5 if register globals is turned on) this creates a serious security vulnerability! an attacker could place SALETYPEVAR=[attackstring] in the query string, and perform an sql injection. i've tried to correct this for you!

you were missing a single quote in two places when assembling your first query, i've fixed that along with a bunch of other tweaks.

in the middle of the script, you were using a variable to calculate the results offset. this variable was being filled with the contents of another variable that when no form was submitted, didn't exist, and when a form was submitted, contained an sql result set... i believe you simply needed to use the variable $limit in the calculation, so i've fixed that.

try this new copy:

search.phpFetching info...

OK you had a tiny error maybe from a type o. It was put like this and was stopping the page from loading.

if (!empty($_POST['sale_type'])) ?

So I fixed that back too:-

if (!empty($_POST['sale_type'])) {

Now when searching for bedrooms and bathrooms the page shows.

When using the search for multiple options for eg 2 bedrooms 1 bathroom and a pool, It will say no properties found.

When a property is found even if it's one, it still fills the page with at least 10 properties and not the one it found. It should only show the properties found and not just refresh the page.

And the code you gave me to help debug I find hard to place in correctly so I don't use it.

  • 0

oops, yeh, i was changing something, then changed my mind, but forgot to change it back...

for the debug code:

---------------------

1) for php error reporting, make sure this is placed early on in your code, which will instruct php to display all errors and warnings

				@ini_set('display_errors', 1);
error_reporting(E_ALL);
define('DEBUGMODE', 'TRUE');

the last line is actually just for your code to use, like: if(defined('DEBUGMODE')){echo 'error i want to display';} which is useful for deciding whether to display sql errors or just a simple fiendly 'problem occured' message.

you may wish to use

ini_set('display_errors', 0);
error_reporting(0);

to disable all error reporting, and then only if the user is logged in, and the user is allowed to view errors, run the above code to enable error reporting.

2) for the sql error reporting code i gave you. first of all you need to include the file that contained the function near the top of your code somewhere.

then you need to use that line of code i gave you in previous threads after each query.

it works like this. after a query is done (mysql_query()), it checks to see if the result of the query is false, if so then an error occurs. if an error occured it ran the die() function which prints whatever message it is given and then kills the script. what we gave die() was first of all whatever was returned from calling the special function, and then a friendly error message. the function when run, checks to see if DEBUGMODE is defined, if not it returns nothing, if so then it returns an sql error message which becomes part of the die() output.

when the special function is called, we give it two pieces of information it can't otherwise get - __LINE__ and __FILE__ - which are the file and line number that php is currently processing.

this is much better that just using or die(mysql_error()) because you can easily control whether sql errors are displayed along side friendly error messages or not, and the sql error messages include information like file and line number.

---------------------

it's pretty tough for me to help with these issues you just posted, because i can't run the code (don't have it all, don't have the database, don't have the sample data, etc).

you need to echo out the sql you're using, and just follow it through, echoing out the contents of variables as you're going along to watch what's happening so you can find where the logic is going wrong. some functions you will find useful are print_r() var_dump() and var_export(), which display the contents of variables (really useful for viewing array contents), results best viewed in your browsers view source code feature.

  • 0

I have uploaded the files that should help you test out the page for errors. Please PM me if something is missing. You will find errors saying missing included file but those files fon't matter.

I would like to get the search page finished do that I can publish the site finally.

test.zipFetching info...

Edited by admin2gd1
  • 0

i tried but it's just a nightmare, i've already spent half an hour hacking away at it trying to work around all the stuff you didn't give me and in the end just had to give up. i really need absolutely everything in order to help, i.e. a copy of absolutely every php file you have, and a dump of the entire database.

  • 0
  theblazingangel said:
i tried but it's just a nightmare, i've already spent half an hour hacking away at it trying to work around all the stuff you didn't give me and in the end just had to give up. i really need absolutely everything in order to help, i.e. a copy of absolutely every php file you have, and a dump of the entire database.

Ok i have redone the files that you need so that you can work properly and uploaded them. So this is what is going on so far.

When searching for properties, the results say how many there are but don't display just those properties the user searched for.

For e.g. you search for a property and one of the values does not match any of the properties it will decide not to tell you how many properties found for any of the other values you searched for.

So for e.g. if you searched for 2 bedrooms 1 bathroom and a pool, and there were either 1 or more properties with 2 bedrooms 1 bathroom and no pool, It will say no properties found.

When a property is found even if it's one, it still fills the page with at least 10 properties and not the one it found. It should only show the properties found and not just refresh the page.

This is what needs fixing.

search.zipFetching info...

  • 0

that stuff was much better, the new attached files should now work.

i fixed the problem by pretty much re-writing search.php, and i've done a bunch of other little fixes in various other files you gave me also, even one of the css files!!! note that you'll need all of the new files for it to work!

please notice that i've completely re-written the way you handle your 'site' information! previously you had a function which fetched that data and stuffed each piece into a global variable. having a large number of global variables like that is horrible! i've replaced this with a neat little class, which fetches the data and keeps it safe for you in an array.

the new way to access this data, is for example, if you want the site keywords: $SITE->getSiteData("site_keywords") i know it's longer to type, but trust me, it's much MUCH easier/tidier/cleaner/etc!!!

also, i noticed that near the top of your copy of search.php you were calling several functions in dbQueries.php, which don't actually do anything! e.g. FindFListing(), this does a database query to fetch some data, but doesn;t print or return it, so it's completely useless. i removed the calls to these, since they were pointless, but i've left the functions for you to cleanup or fix, yourself.

--

Before you go off and play with the new code though, i want you to do something! i want to show you exactly why you need to make more effort to get php to display all errors to you.

1) get a copy of the new common.inc.php file from includes/ that i made

2) in the copy of search.php from your last post, right at the start of the code, just after <?php, place require_once("includes/common.inc.php");

3) fill in your database info in constants.php

now, run search.php and see how many errors you get! you should be seeing a ton of them! this is exactly why you want to have php display ALL errors and warnings! i've had to go through all of your code and fix every last one of them, never mind fixing the bug you had with showing the correct listings (which was because you weren't adding the search data to the final query btw) which took a big re-write to put right.

i think someone owe's me a drink ;)

search.zipFetching info...

  • 0

I haven't checked what u asked me to do just yet, I have been busy looking and testing the new search page u have kindly fixed for me.

OK the search page is working wonderful but I need to get a 3 things corrected before it is complete.

1. The price needs to search a range between min and max. I have placed 2 fields for the price and I also added a function to display which field is min and max but they dont show becuase of a value that already exists so it looks like this.

onblur="this.value=(this.value=='') ? 'min' : this.value;" onfocus="this.value=(this.value=='min '' : this.value;" value="&lt;?php echo $criteria_price; ?&gt;"

It's supposed to be like this to show either min or max.

onblur="this.value=(this.value=='') ? 'min' : this.value;" onfocus="this.value=(this.value=='min '' : this.value;" value="min"

2. The Sq. m? needs to search a range but I still only want one field.

3. This code doesn't seem to show up when no properties found.

&lt;?php
if ($totalRecordsFound === 0)
{
?&gt;
		&lt;table width="998" cellspacing="0"&gt;
			&lt;tr&gt;
				&lt;td colspan="3"&gt;None found!&lt;/td&gt;
			&lt;/tr&gt;
		&lt;/table&gt;

So can that be removed?

I added garage so people can search properties with garages and that works.

Also the changes you made to SITEinfo, does not work except for the SITEtitle.

This bit, I just forgot to remove from that page as this function is for all the other pages.

  Quote
also, i noticed that near the top of your copy of search.php you were calling several functions in dbQueries.php, which don't actually do anything! e.g. FindFListing(), this does a database query to fetch some data, but doesn;t print or return it, so it's completely useless. i removed the calls to these, since they were pointless, but i've left the functions for you to cleanup or fix, yourself.

In the dbQueries.php file, you changed this in some of the queries, Why?

//$VIDEOtype = $row["video_type"]; //field does not exist in database at this time!
//$VIDEOfile = $row["video_file"]; //field does not exist in database at this time!

All the other tweaks I am very grateful for your hard work and time.

search2.phpFetching info...

Edited by admin2gd1
  • 0

a couple new files for you:

search.phpFetching info... lang.phpFetching info...

the new search.php allows specifying a range for size and price, and fixes the "zero results" bug

the new lang.php fixes a couple of bugs i spotted

the new site info method i implemented for you works perfectly for me. if you want say the site's title, you get it like echo $SITE->getSiteData("site_title");

the bit in the quotes is the name of the field in the database table!

in dbQueries.php i did this

//$VIDEOtype = $row["video_type"]; //field does not exist in database at this time!
//$VIDEOfile = $row["video_file"]; //field does not exist in database at this time!

because the fields 'video_type' and 'video_file' don't exist in the database table! if you add these fields to the database table then un-comment these two lines!

  • 0

Thats great thanks, the search works perfect but I do have a question as to why when I copied the function for searching rang for price and meters that it does not work for bedrooms and bathrooms.

Can you have a quick check at the code I have put for both bedrooms and bathrooms. It will only search min on both and not max. I might of overlooked something, I don't know but it looks ok in the code so just check just in case.

Plus is it possible (now that you have re-written the search page) to add a function that allows the user to view the properties they searched in order of price high or low.

I left a piece of code hidden for this function to be written in the future. It will look like this.

&lt;!--Sort by: highest | lowest--&gt;

And the video queries I think I added but did'nt give you the upto datadase structure so they do work.

Thanks for your time and hardwork again.

EDIT:- Just added more properties to test the pagenation and it works when you haven't searched any properties and you are just browsing all the properties, but when you search and you have another page of results, when you go to that page it does not continue the results found and removes the search criteria the user put. Can you fix this also please thanks.

search.phpFetching info...

Edited by admin2gd1
  • 0

i've fixed the bug with bedrooms/bathrooms min/max, you'd just simply used = instead of >= and <= where the bits of the query are compiled (lines 93-96)

search.phpFetching info...

the search parameters not being carried over to further pages in the search form i had noticed, however i overlooked the fact that the listings therefore are no longer dependent on the search parameters.

there are two ways of solving this

a) we could change the form's method (in your html) from POST to GET, this would mean that the form data is attached to the url like search.php?category=xxxxx&department=xxxxxx&price_min=30000&price_max=50000.... etc

you would then access the data like $_GET['category'] instead of $_POST['category']

to get the data to work across pages, you need to add the data like above, to the page links

b) you could save the search parameters in the session or even a cookie, this would also allow the search data to survive across pages.

there can be problems with this approach though, what if a user opens two copies of the search page, and tries to do a different search in each one! to allow for this (which you definitely should), you need to assign a unique, random identifier to each search. and you could potentially have memory issues on the server if you're storing a large number of search parameter sets.

as for allowing the user to sort by different fields, you need to add input fields to allow the user to specify what they want. some systems may be designed so you can click on a column heading in a table, which is set as a hyper link, which specifies the column in the url, and the direction (asc/desc). clicking a second time, should change from asc to desc, or visa-versa.

in your case it might be best to have two select fields in a form, one to specify the 'column', and one to specify ASC/DESC. you should then take this data with your backend code, and create the ORDER BY part of your query from it, which you can then use in your queries.

  • 0

OK I have changed the form to get instead of post and added the links to the pages so that it carries on the search and it works great. I have put the 2 fields for change the order by type but not sure how to place it in as i have never done this ever before.

Here is what I have added.

&lt;form class="searchoptions" method="GET" action="&lt;?php echo $_SERVER['PHP_SELF']; ?&gt;"&gt;
Order
&lt;select class="select" name="order" size="1" style="height: 22px"&gt;
&lt;option value="department"&gt;Department&lt;/option&gt;&lt;!-- This only shows if the user searches for properties in any department --&gt;
&lt;option value="category"&gt;Category&lt;/option&gt;&lt;!-- This only shows if the user searches any type of property --&gt;
&lt;option value="price"&gt;Price&lt;/option&gt;
&lt;option value="bedrooms"&gt;Bedrooms&lt;/option&gt;
&lt;option value="bathrooms"&gt;Bathrooms&lt;/option&gt;					
&lt;option value="garage"&gt;Garage&lt;/option&gt;&lt;!-- This only shows if the user searches any property with a garage --&gt;
&lt;option value="pool"&gt;Pool&lt;/option&gt;&lt;!-- This only shows if the user searches any property with a pool --&gt;
&lt;option value="meters"&gt;Meters&lt;/option&gt;
&lt;/select&gt;
by
&lt;select class="select" name="by" size="1"&gt;
&lt;option value="DESC"&gt;High&lt;/option&gt;
&lt;option value="ASC"&gt;Low&lt;/option&gt;
&lt;/select&gt;
&lt;input class="find" name="submit" type="submit" value="Go"&gt;
&lt;/form&gt;

Now on some of the options for ordering by I don't want them to display if the user has select that option specific in the search. E.G. Department will not show in the options list if the user has selected to search properties in Aude.

Also I have a side search on many other pages with the same values the user can search for and it is sent to the search page to display the results. The only thing is it does not collect the information the user has asked for. Does another function needs to be added to collect the users input from another page or do I copy the functions you have written for me on the search page and copy it to the other pages were the side search is placed?

search_order_form.phpFetching info...

Edited by admin2gd1
  • 0

for your ordering form, you can either make it a part of your existing search form, which would probably be the most simple. otherwise, for the two forms, you will need to add the others existing data to the end of the url in the action attribute.

i'm not sure why you would not want 'department' to be in the list when searching for propertes in 'Aude', but all you'd need to do is add some code to decide whether to output the html for that option or not, and whether or not to accept that option at the validation stage (should the option be made available by mistake, or if someone uses a modified html file to submit a form).

if you have search boxes on other pages which direct to this search page, for them to work, all you need to do is:

1) make sure the form is the same as the main one (since our processing code displays an error if a field is missing), or disable the lines of code that produce an error (lines 55 to 66) if it isn't

2) make sure these forms also submit via GET rather than POST

  • 0

OK this is my side search that goes into the first column of three. I have the fields and I have set it to get. Now I have tested it and in the address bar it shows what I have searched for but does not display the results on the search page. Now I think this could be because if I search on the search page I get in the address bar something like this.

http://www.website.com/search.php?department=Aude&category=Maison&bedrooms_min=2&bedrooms_max=4&bathrooms_min=2&bathrooms_max=4&price_min=200000&price_max=300000&size_min=100&size_max=200&garage=any&pool=any&submit=Search

but if I search on the side search that is shown on other pages, I get this.

http://www.website.com/search.php?category=Maison&department=Aude&bedrooms_min=2&bedrooms_max=4&bathrooms_min=2&bathrooms_max=4&price_min=200000&price_max=300000&size_min=100&size_max=200&pool=any&garage=any&Search=SEARCH+PROPERTIES!

Now notice that the category on the second code is first and the department is second. Is that causing the problem?

I don't think the text displayed in the search button matters that they are different or does it?

I also put this part of the code to see if it helped but it made no difference.

&lt;?php
// initialize search query
$sqlWhere = '';

if (isset($_GET['submit'])) {

	// Check form fields

		// NOTE you should not include checks here for checkbox inputs, as they will always fail the following sort of check when the they are unticked!

		$fieldMissing = false;
		if (! isset($_GET['category'])) { $fieldMissing = true; }
		if (! isset($_GET['department'])) { $fieldMissing = true; }
		if (! isset($_GET['price_min'])) { $fieldMissing = true; }
		if (! isset($_GET['price_max'])) { $fieldMissing = true; }
		if (! isset($_GET['bedrooms_min'])) { $fieldMissing = true; }
		if (! isset($_GET['bedrooms_max'])) { $fieldMissing = true; }
		if (! isset($_GET['bathrooms_min'])) { $fieldMissing = true; }
		if (! isset($_GET['bathrooms_max'])) { $fieldMissing = true; }
		if (! isset($_GET['pool'])) { $fieldMissing = true; }
		if (! isset($_GET['garage'])) { $fieldMissing = true; }
		if (! isset($_GET['size_min'])) { $fieldMissing = true; }
		if (! isset($_GET['size_max'])) { $fieldMissing = true; }

		if ($fieldMissing) { die('Error: One or more fields missing from submitted form!'); }

	// Get form data

		$criteria_category = mysql_real_escape_string($_GET['category']);
		$criteria_department = mysql_real_escape_string($_GET['department']);
		$criteria_price_min = mysql_real_escape_string($_GET['price_min']);
		$criteria_price_max = mysql_real_escape_string($_GET['price_max']);
		$criteria_bedrooms_min = mysql_real_escape_string($_GET['bedrooms_min']);
		$criteria_bedrooms_max = mysql_real_escape_string($_GET['bedrooms_max']);
		$criteria_bathrooms_min = mysql_real_escape_string($_GET['bathrooms_min']);
		$criteria_bathrooms_max = mysql_real_escape_string($_GET['bathrooms_max']);
		$criteria_pool = mysql_real_escape_string($_GET['pool']);
		$criteria_garage = mysql_real_escape_string($_GET['garage']);
		$criteria_size_min = mysql_real_escape_string($_GET['size_min']);
		$criteria_size_max = mysql_real_escape_string($_GET['size_max']);

	// Validate form data

		// here you should check the form data is valid, like checking numbers actually are numbers
		// for lists, you should get an array of list items and check that it the data submitted is a real item in the list

		// for now we will **TEMPORARILY** just force (typecast) a couple of variables to type int, and you can replace this with validation checks later!
		if ($criteria_price_min != '') { $criteria_price_min = (int) $criteria_price_min; }
		if ($criteria_price_max != '') { $criteria_price_max = (int) $criteria_price_max; }
		if ($criteria_bedrooms_min != '') { $criteria_bedrooms_min = (int) $criteria_bedrooms_min; }
		if ($criteria_bedrooms_max != '') { $criteria_bedrooms_max = (int) $criteria_bedrooms_max; }
		if ($criteria_bathrooms_min != '') { $criteria_bathrooms_min = (int) $criteria_bathrooms_min; }
		if ($criteria_bathrooms_max != '') { $criteria_bathrooms_max = (int) $criteria_bathrooms_max; }
		if ($criteria_size_min != '') { $criteria_size_min = (int) $criteria_size_min; }
		if ($criteria_size_max != '') { $criteria_size_max = (int) $criteria_size_max; }

	// Compile WHERE clause for query

		$clauseArr = array();

		if ( ($criteria_category != '') &amp;&amp; ($criteria_category != 'any') ) { $clauseArr['cat'] = "AND `category`='{$criteria_category}'"; }
		if ( ($criteria_department != '') &amp;&amp; ($criteria_department != 'any') ) { $clauseArr['dept'] = "AND `department`='{$criteria_department}'"; }
		if ($criteria_price_min != '') { $clauseArr['price_min'] = "AND `price`&gt;='{$criteria_price_min}'"; }
		if ($criteria_price_max != '') { $clauseArr['price_max'] = "AND `price`&lt;='{$criteria_price_max}'"; }
		if ($criteria_bedrooms_min != '') { $clauseArr['bedrooms_min'] = "AND `bedrooms`&gt;='{$criteria_bedrooms_min}'"; }
		if ($criteria_bedrooms_max != '') { $clauseArr['bedrooms_max'] = "AND `bedrooms`&lt;='{$criteria_bedrooms_max}'"; }
		if ($criteria_bathrooms_min != '') { $clauseArr['bathrooms_min'] = "AND `bathrooms`&gt;='{$criteria_bathrooms_min}'"; }
		if ($criteria_bathrooms_max != '') { $clauseArr['bathrooms_max'] = "AND `bathrooms`&lt;='{$criteria_bathrooms_max}'"; }
		if ( ($criteria_pool != '') &amp;&amp; ($criteria_pool != 'any') ) { $clauseArr['pool'] = "AND `pool` LIKE '{$criteria_pool}'"; }
		if ( ($criteria_garage != '') &amp;&amp; ($criteria_garage != 'any') ) { $clauseArr['garage'] = "AND `garage` LIKE '{$criteria_garage}'"; }
		if ($criteria_size_min != '') { $clauseArr['size_min'] = "AND `meters`&gt;='{$criteria_size_min}'"; }
		if ($criteria_size_max != '') { $clauseArr['size_max'] = "AND `meters`&lt;='{$criteria_size_max}'"; }

		if (! empty($clauseArr)) { $sqlWhere = implode(' ', $clauseArr); }

} else {

	$criteria_category = 'any';
	$criteria_department = 'any';
	$criteria_price_min = '';
	$criteria_price_max = '';
	$criteria_bedrooms_min = '';
	$criteria_bedrooms_max = '';
	$criteria_bathrooms_min = '';
	$criteria_bathrooms_max = '';
	$criteria_pool = 'any';
	$criteria_garage = 'any';
	$criteria_size_min = '';
	$criteria_size_max = '';
}

?&gt;

So again I am :unsure: !

search.phpFetching info...

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Posts

    • Another reason to stick with Firefox
    • Yes, the Control Pannel issue has been fixed. As I ask when people claim it hasn't, can you name a single thing in Windows 11 that can only be done by opening Control Panel? Your comment about Error 0x80070643 is so asinine that I debated if you were worth a reply, but here I am. The article mentioned a VERY specific issue with the WinRE partition size being too small in Windows 10 and preventing updates from being installed unless you reinstalled or manually fixed it. That issue does not exist on Windows 11, period. To point to random issues with Windows updates on 11 that don't affect everyone and don't involve that issue is being dishonest. Had the article said "Issues with updates, such as..." then I'd agree with you, but it didn't, it simply mentioned that one specific issue, which despite your claim, does not exist on 11 or on newer builds of 10 (so the article is kind of wrong, it did get fixed, just not gracefully). As far as UX/UI comes more down to opinion, but again, you are saying it is "terrible" which has nothing to do with consistency. Windows 11 has a more consistent interface. You are welcome to say it is constantly bad, but I don't see how any objective person can say it isn't more constant than Windows 10's unholy merger of Windows 7 and Windows 8. To be fair, I really like Windows 10's interface, it worked great, but was it consistent, NO, it was one of the least consistent interfaces MS has ever made. I agree with the lack of competition. Linux continues to get better
    • Microsoft isn't happy you're using unsupported Exchange versions, announces final deadline by Usama Jawad Earlier this month, Microsoft announced Exchange Server Subscription Edition (SE), which is the official transition of the product to the Modern Lifecycle Policy, where software is continuously serviced without an end-of-life date, as long as you keep it updated. It also revealed surprising, but brief, Extended Security Updates (ESUs) for Exchange 2016 and 2019. As it winds down support for these products, the company has expressed some displeasure that some customers are using even older and, obviously, unsupported versions of Exchange. In a blog post, the company has noted that it currently offers migration tools that enable the migration of public folders from on-premise Exchange 2013 or older versions to Exchange Online. This is by design, but Microsoft is now changing its tune on the topic. Starting from October 1, 2025, customers leveraging Exchange 2010 or older versions of the software will not be allowed to use Microsoft's tools to migrate their public folders to Exchange Online. Microsoft believes that this deprecation will reduce reliance on legacy systems and enhance "long-term service reliability". Any migrations that are attempted after the aforementioned date will fail, so Microsoft has urged customers to complete their migrations as soon as possible. If customers want to move their data to Exchange Online after October 1, they will first have to upgrade to a newer Exchange version, which is Exchange 2013, but it is important to keep in mind that supported versions are 2016 and 2019. Microsoft has emphasized in a rather stern tone that it does not encourage using unsupported versions of Exchange Server at all, and it has just put out this advisory because it is aware that public folder migrations from legacy systems are currently active, even though they shouldn't be. Needless to say, customers should upgrade to Exchange Server 2016 or 2019 as quickly as possible, but ideally, they should consider moving to Exchange Server SE at this point, considering that the other two versions are running out of support soon, too.
    • A little bit, yeah, if you ask me. Granted, he has the right to be upset with this jerk user that attacked him, but why drop the entire project just because of ONE person? Seems a little exaggerated.
  • Recent Achievements

    • Week One Done
      NeoWeen earned a badge
      Week One Done
    • One Month Later
      BA the Curmudgeon earned a badge
      One Month Later
    • First Post
      Doreen768 earned a badge
      First Post
    • One Month Later
      James_kobe earned a badge
      One Month Later
    • Week One Done
      James_kobe earned a badge
      Week One Done
  • Popular Contributors

    1. 1
      +primortal
      673
    2. 2
      ATLien_0
      256
    3. 3
      Xenon
      165
    4. 4
      neufuse
      145
    5. 5
      +FloatingFatMan
      115
  • Tell a friend

    Love Neowin? Tell a friend!