Gossamer Forum
Home : Products : DBMan : Installation :

Searching in the length field

Quote Reply
Searching in the length field
Hi JPDeni,

Back again, I'm trying to search in the length field, and using the mod you did for me earlier, the data is stored in 4 fields in the database as follows;

Length Unit Feet Meters
| 32 | Feet | 32 | 10.5 |

however trying to search has me stuck. I have
used your build_fancy_select_fields mod to create a range search with two select fields length-gt and length-lt , with a radio button field named unit with the values feet and meters.

This is the code you wrote to work out the feet/meters values given the other value:

Code:
if ($in{'Length'}) {
if ($in{'Unit'} eq "Feet") {
$in{'Feet'} = $in{'Length'};
$in{'Meters'} = ($in{'Length'} / 3.048);
$in{'Meters'} = sprintf("%.1f",$in{'Meters'});
} else {
if ($in{'Unit'} eq "Meters") {
$in{'Meters'} = $in{'Length'};
$in{'Feet'} = ($in{'Meters'} * 3.048);
$in{'Feet'} = sprintf("%.1f",$in{'Feet'});
}
}
}

I know that when I search using this method it passes the unit value feet/meters although I don't want to search in only one field.

I need to search in two fields, meters/feet, the value stored in length is the same as which field is selected when it is entered eg: if someone enters 45 and selects from radio button meters,field length becomes 45.

Length Unit Feet Meters
| 45 | Meters | 138 | 45 |



The only real important fields for searching are feet/meters, do you know of any way to search both of these fields at once using a range search as I have set up.

Sorry I don't think I have explained it clearly, see what you think. Smile




[This message has been edited by fordy (edited July 07, 1999).]
Quote Reply
Re: Searching in the length field In reply to
Hi JPDeni,

Sorry I knew it was confusing Smile, I've worked it out a bit clearer.
As you said I enter

Quote:

I want to find something that is greater than 30 feet and less than 150 feet. So I enter those search terms in the "Length-gt" and "Length-lt" fields. Also, I select a radio button that tells it to look for "Feet" and not "Meters."

Yes this is how I wanted to set it up so that it requires only one group of select fields to enter in the search. eg

select field one length-gt
and
select field two length-lt
and a radio button field.(meters/feet)
Quote:
You want the query subroutine to look at the unit and end up searching for
Feet-gt = 30
Feet-lt = 150
Yes but I also need it to search for the equivalent in meters also.

I have come up with a simple solution although the other is more desirable if it can be done. I have simply created a set of select fields for meters and another for feet. However to search this means that only one option must be selected.

It would be better (to prevent errors) to provide only one select field and a radio button.

The fields length and unit are not really required in the database. I think another solution may lie in some javascripting which I tried first but gave up on ( and I know you don't deal with java Smile). I would like to stay away from javascripts also if you think it can be done.
Smile

Thanks for your help again JPDeni. Smile
Quote Reply
Re: Searching in the length field In reply to
Right. You don't need the "Length" and "Units" fields, unless you want to keep the same formatting that users entered in the first place when the search results are displayed.

I'm wondering why you need to search on both the Feet and Meters field.


------------------
JPD





Quote Reply
Re: Searching in the length field In reply to
It was a long time ago when I gave you that code. Smile That was for the add_record subroutine, right?

I'm still not completely sure about what you want to do. I'll give an example of what I think you want to do and you tell me if I'm right, okay?

I want to find something that is greater than 30 feet and less than 150 feet. So I enter those search terms in the "Length-gt" and "Length-lt" fields. Also, I select a radio button that tells it to look for "Feet" and not "Meters."

You want the query subroutine to look at the unit and end up searching for
Feet-gt = 30
Feet-lt = 150

Right?

I know how to do the above, but I'm going to wait to be sure I understand correctly so I don't type in a whole lot of stuff you can't use. Smile


------------------
JPD







[This message has been edited by JPDeni (edited July 08, 1999).]
Quote Reply
Re: Searching in the length field In reply to
Hi JPDeni,


Code:

if ($in{'Length'}) {
if ($in{'Unit'} eq "Feet") {
$in{'Feet'} = $in{'Length'};
$in{'Meters'} = ($in{'Length'} / 3.048);
$in{'Meters'} = sprintf("%.1f",$in{'Meters'});
} else {
if ($in{'Unit'} eq "Meters") {
$in{'Meters'} = $in{'Length'};
$in{'Feet'} = ($in{'Meters'} * 3.048);
$in{'Feet'} = sprintf("%.1f",$in{'Feet'});
}
}
}

be written differently so as to eliminate the extra fields ( I think you've already answered this ) and I've probably answered all my questions too.

Thanks anyway as usual,

Fordy Smile.

Quote Reply
Re: Searching in the length field In reply to
What I would do is this--

I would keep the Length and Unit fields if I wanted to maintain the original entry format for the record, and also convert it into meters. The Length and Unit fields would be for display only. The search would be done solely on the meters field.

If I didn't care about that, I would convert all lengths to meters when the record is added. This would eliminate three fields in your database. I would just keep the meters field.

If people wanted to search by feet, I would compute the number of meters and perform the search in terms of meters. Then, if they requested a search in feet, the result would be converted to feet. Otherwise, the result would be in meters.

What d'ya think? Smile

------------------
JPD





Quote Reply
Re: Searching in the length field In reply to
Thanks JPDeni,

I'll try what you suggested in the next few days.

Thanks for your input so far. Smile

Fordy.