Cable Forum

Cable Forum (https://www.cableforum.uk/board/index.php)
-   Internet Discussion (https://www.cableforum.uk/board/forumdisplay.php?f=25)
-   -   Help (again) ... (https://www.cableforum.uk/board/showthread.php?t=14313)

Bifta 03-07-2004 12:22

Help (again) ...
 
I'm having trouble with a search form, normally when I click submit it'll encode the URL with the form parameters, e.g.

http://www.url.com/results.php?minpr...sort=Price+ASC

The problem I have is with "furnishing" which is a drop down menu

<select name="furnishing">
<option value="Furnished">Furnished
<option value="Unfurnished">Unfurnished
<option value="Part furnished">Part furnished
<option value="Furnished to suit">Furnished to suit
<option>No preference</option>
</select>

If I select an option, e.g. "furnished" from the drop down menu, it shows results, if I pick no preference it'll encode the url with "furnishing=" and show no results, is there something I can put in to the results page to show all types of furnishing or is there something I can do to the form to make it work?

Thanks

Richard M 03-07-2004 12:32

Re: Help (again) ...
 
You should really be using the closing </option> tags and put 'selected="selected"' in the default option.
e.g.:

<select name="furnishing">
<option value="Furnished">Furnished</option>
<option value="Unfurnished">Unfurnished</option>
<option value="Part furnished">Part furnished</option>
<option value="Furnished to suit">Furnished to suit</option>
<option value="No preference" selected="selected">No preference</option>
</select>

Bifta 03-07-2004 12:40

Re: Help (again) ...
 
Quote:

Originally Posted by Richard M
You should really be using the closing </option> tags and put 'selected="selected"' in the default option.
e.g.:

<select name="furnishing">
<option value="Furnished">Furnished</option>
<option value="Unfurnished">Unfurnished</option>
<option value="Part furnished">Part furnished</option>
<option value="Furnished to suit">Furnished to suit</option>
<option value="No preference" selected="selected">No preference</option>
</select>

Must have missed that heh, anyway it's now:

<select name="furnishing">
<option value="Furnished">Furnished</option>
<option value="Unfurnished">Unfurnished</option>
<option value="Part furnished">Part furnished</option>
<option value="Furnished to suit">Furnished to suit</option>
<option value="">No preference</option>
</select>

You see, there is no value in the database for "No Preference", so I want it to just somehow bypass the "furnishing" field somehow, I thought that furnishing= (with nothing after it) would show them all, but .. it doesn't :( which is a bit odd, because if I set one of the other fields to say minbeds= (with nothing after it) it shows all the results. which is probably due to:

if ($minprice == "")
{
$minprice = 0;
}

in the results page. I just need to get something in there for furnishing (somehow)

Mr_love_monkey 03-07-2004 12:49

Re: Help (again) ...
 
if you're using a database can't you just have it so that no preference uses a wildcard instead '%'?

Bifta 03-07-2004 12:50

Re: Help (again) ...
 
Quote:

Originally Posted by Mr_love_monkey
if you're using a database can't you just have it so that no preference uses a wildcard instead '%'?

Ohh, let me give that a try.

edit: A cunning idea that used to work with an ASP based property search, but for some reason doesn't work with this, still no records shown. :(

Mr_love_monkey 03-07-2004 12:58

Re: Help (again) ...
 
What are you using to do this?

Richard M 03-07-2004 12:59

Re: Help (again) ...
 
Quote:

Originally Posted by Bifta
Must have missed that heh, anyway it's now:

<select name="furnishing">
<option value="Furnished">Furnished</option>
<option value="Unfurnished">Unfurnished</option>
<option value="Part furnished">Part furnished</option>
<option value="Furnished to suit">Furnished to suit</option>
<option value="">No preference</option>
</select>

You see, there is no value in the database for "No Preference", so I want it to just somehow bypass the "furnishing" field somehow, I thought that furnishing= (with nothing after it) would show them all, but .. it doesn't :( which is a bit odd, because if I set one of the other fields to say minbeds= (with nothing after it) it shows all the results. which is probably due to:

if ($minprice == "")
{
$minprice = 0;
}

in the results page. I just need to get something in there for furnishing (somehow)

No, what you'll need is this...
Use the HTML that I described in my post, you shouldn't use a blank value but the below code will still work anyway.

PHP Code:

<?php
if (isset($_GET['furnishing'])) {
$preference = $_GET['furnishing'];
$dbconnect = mysql_connect("localhost", "username", "password");
$dbname = "database name";
$tablename = "table name";

// If the "furnishing" field is empty (i.e. "") then do this:
if (empty($furnishing)) {
if (!
$dbconnect) {
echo 
mysql_error();
exit;
}
if (!
mysql_select_db($dbname)) {
echo 
mysql_error();
exit;
}
$sql = mysql_query("SELECT * FROM `$tablename`");
if (!
$sql) {
echo 
mysql_error();
exit;
}
while (
$sql_data = mysql_fetch_array($sql))
{
$price = $sql_data['price'];
// etc for each field you need
echo "Price: " . $price . "<br />";
}
mysql_free_result($sql);
mysql_close($dbconnect);
}

// If the "furnishing" field contains a value then do this:
else {
if (!
$dbconnect) {
echo 
mysql_error();
exit;
}
if (!
mysql_select_db($dbname)) {
echo 
mysql_error();
exit;
}
$sql = mysql_query("SELECT * FROM `$tablename` WHERE furnishing='$furnishing'");
if (!
$sql) {
echo 
mysql_error();
exit;
}
while (
$sql_data = mysql_fetch_array($sql))
{
$price = $sql_data['price'];
// etc for each field you need
echo "Price: " . $price . "<br />";

}
mysql_free_result($sql);
mysql_close($dbconnect);
}
}
?>

I haven't tested this but it should work.

Bifta 03-07-2004 13:23

Re: Help (again) ...
 
Quote:

Originally Posted by Richard M
No, what you'll need is this...
Use the HTML that I described in my post, you shouldn't use a blank value but the below code will still work anyway.

PHP Code:

<?php
if (isset($_GET['furnishing'])) {
$preference = $_GET['furnishing'];
$dbconnect = mysql_connect("localhost", "username", "password");
$dbname = "database name";
$tablename = "table name";

// If the "furnishing" field is empty (i.e. "") then do this:
if (empty($furnishing)) {
if (!
$dbconnect) {
echo 
mysql_error();
exit;
}
if (!
mysql_select_db($dbname)) {
echo 
mysql_error();
exit;
}
$sql = mysql_query("SELECT * FROM `$tablename`");
if (!
$sql) {
echo 
mysql_error();
exit;
}
while (
$sql_data = mysql_fetch_array($sql))
{
$price = $sql_data['price'];
// etc for each field you need
echo "Price: " . $price . "<br />";
}
mysql_free_result($sql);
mysql_close($dbconnect);
}

// If the "furnishing" field contains a value then do this:
else {
if (!
$dbconnect) {
echo 
mysql_error();
exit;
}
if (!
mysql_select_db($dbname)) {
echo 
mysql_error();
exit;
}
$sql = mysql_query("SELECT * FROM `$tablename` WHERE furnishing='$furnishing'");
if (!
$sql) {
echo 
mysql_error();
exit;
}
while (
$sql_data = mysql_fetch_array($sql))
{
$price = $sql_data['price'];
// etc for each field you need
echo "Price: " . $price . "<br />";

}
mysql_free_result($sql);
mysql_close($dbconnect);
}
}
?>

I haven't tested this but it should work.

Cheers, that would be a bit tough to fit around my current queries though, what might be easier (if I had ANY clue how to do it) is to stop "furnishing" appearing in the URL string completely if they select "No Preference", must be some way of doing this with PHP in the actual form.

Mr_love_monkey 03-07-2004 13:35

Re: Help (again) ...
 
Quote:

Originally Posted by Bifta
(if I had ANY clue how to do it) is to stop "furnishing" appearing in the URL string completely if they select "No Preference", must be some way of doing this with PHP in the actual form.

hmm.. well at the risk of using a sledgehammer to crack a walnut...

What you could do is have the select box outside of the html form, if your layout will allow that, then have an onsubmit javascript coming off the button that grabs the select details and decides to add it in, by dyamically adding an element to your search form.

If that makes sense... but it does seem a bit of over kill

Richard M 03-07-2004 13:36

Re: Help (again) ...
 
It's not really possible to stop the browser sending the "furnishings" value, even if it's empty - other than Javascript but you can't always rely on this.
This PHP code deals with it though:

PHP Code:

if (empty($_GET['furnishing'])) {
/* if the value in the URL is empty like:
http://www.site.com/results.php?furnishing=
then do something here...
*/
}
elseif (!empty(
$_GET['furnishing'])) {
/* if the a value for "furnishing" passed in the URL is like:
http://www.site.com/results.php?furnishing=Fully+Furnished
then do something different
*/
} 


Bifta 03-07-2004 13:37

Re: Help (again) ...
 
Quote:

Originally Posted by Mr_love_monkey
hmm.. well at the risk of using a sledgehammer to crack a walnut...

What you could do is have the select box outside of the html form, if your layout will allow that, then have an onsubmit javascript coming off the button that grabs the select details and decides to add it in, by dyamically adding an element to your search form.

If that makes sense... but it does seem a bit of over kill

Unfortunately the way it's layed out wouldn't allow me to do that, thanks though.

The only other thing I can think of is to have say "No Preference" set to a value, then the results page does something like if ($furnishing = "whatevervalue") {do something beyond my capabilities to show all furnishing types}

If that makes any sense :D

Bifta 03-07-2004 13:40

Re: Help (again) ...
 
Quote:

Originally Posted by Richard M
It's not really possible to stop the browser sending the "furnishings" value, even if it's empty - other than Javascript but you can't always rely on this.
This PHP code deals with it though:

PHP Code:

if (empty($_GET['furnishing'])) {
/* if the value in the URL is empty like:
[url]http://www.site.com/results.php?furnishing=[/url]
then do something here...
*/
}
elseif (!empty(
$_GET['furnishing'])) {
/* if the a value for "furnishing" passed in the URL is like:
[url]http://www.site.com/results.php?furnishing=Fully+Furnished[/url]
then do something different
*/
} 


Heh, that's almost what I said :) It's the "do something here" bit that baffles me (sorry, I still know very little about PHP and it's probably very infuriating for people trying to help me)

Richard M 03-07-2004 13:46

Re: Help (again) ...
 
No preference should really be set to a value.
The code I posted first of all will help with that, especially the second part:

// If the "furnishing" field contains a value then do this:
$sql = mysql_query("SELECT * FROM `$tablename` WHERE furnishing='$furnishing'");


All times are GMT. The time now is 22:57.

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2026, vBulletin Solutions Inc.
All Posts and Content are © Cable Forum