Jump to content

Archived

This topic is now archived and is closed to further replies.

REOL

help with form hanadling/query

Recommended Posts

i need to help query out the following;

[code]<FORM method="get" name="find" action="<?php $_SERVER['PHP_SELF'] ?>">

<table>
<tr>
<td align="center" colspan="3"><span class="formheadsmall">Rent ($ per Square Foot)</span></td>
<td></td>
<td colspan="3" align="center"><span class="formheadsmall">Square Footage</span></td>
</tr>
<tr>
<td valign="top">
<span class="formheadsmall">Minimum</span><br>
<input class="small" type="text" size="5" name="minimum_rent" value="0" /></td>
<td><img src="images/null.gif" height="1" width="24"></td>
<td valign="top"><span class="formheadsmall">Maximum</span><br>
<input class="small" type="text" size="5" name="maximum_rent" value="300" /></td>
<td><img src="images/null.gif" width="48"></td>
<td valign="top"><span class="formheadsmall">Minimum</span><br>
<input class="small" type="text" size="5" name="minimum_space" value="0" /></td>
<td><img src="images/null.gif" height="1" width="24"></td>
<td valign="top"><span class="formheadsmall">Maximum</span><br>
<input class="small" type="text" size="5" name="maximum_space" value="200000" /></td>
</tr>
</table>
<table>
<tr>
<td><span class="formheadsmall">Office :: Retail</span><br>
<select class="small" name="isRetail">
<option value="-1">ALL</option>
<option value="0">Office</option>
<option value="1">Retail</option></select></td>
<td><img src="images/null.gif" height="1" width="24"></td>
<td><span class="formheadsmall">Prebuilt</span><br>
<select class="small" name="isPrebuilt">
<option value="-1">ALL</option>
<option value="1">Yes</option>
<option value="0">No</option></select></td>
</tr>
</table><br><table>
<tr>
<td valign="top"><span class="formheadsmall">Properties</span><br>
<select class="small" multiple="yes" size="4" name="PropertyList">
<option value="all" selected>All Properties</option>
<?
$properties = getProperties( 'id' );
foreach ( $properties as $property )
{
$selected = ($property_id == $property['id']) ? "selected" : "";
echo "<option $selected value='$property[id]'>$property[address]</option>";
}
?>
</select>
</td>
<td><img src="images/null.gif" height="1" width="18"></td>
<td valign="top">
<span class="formheadsmall">District</span><br>
<select class="small" multiple="yes" size="4" name="DistrictList">
<option value="all" selected>All Districts</option>
<?
$districts = getDistricts();
foreach ( $districts as $district )
{
$selected = ($district_id == $district['id']) ? "selected" : "";
echo "<option value='$district[districtid]'>$district[name]</option>";
}
?>
</select></td>
</tr>
<tr><td><img src="images/null.gif" width="1" height="6"></td></tr>
<tr>
<td><span class="formheadsmall">Sort Results</span><br>
<select class="small" name="sort">
<option value="0">By Property/Floor</option>
<option value="1">By Rent</option>
<option value="2">By Square Footage</option>
</select></td>
<td><img src="images/null.gif" height="1" width="6"></td>
<td valign="bottom" align="left"><input class="button" type="submit" value="Find Space" name="search" /></td>
</tr>
</table>
</form>[/code]


just need the correct way to input all values and find a common entity, in this case its  property_id


anyhelp would be great.  thanks.

Share this post


Link to post
Share on other sites
a user will search using those fields and get a result by a property id#

Share this post


Link to post
Share on other sites
[code]function getProperties( $sortcol = 'buildingcode')
{
$query = "SELECT * FROM property WHERE isactive='t' order by $sortcol";
$result = pgdbsql( $query, "web" );
return $result;
}

function getProperty( $property_id )
{
$query = "SELECT * FROM property WHERE id = $property_id";
$result = pgdbsql( $query, "web" );
return $result[0];
}

function getPropertyDistricts( $property_id )
{
$query = "SELECT districtid FROM propertydistrict WHERE propertyid = $property_id";
$result = pgdbsql( $query, "web" );

$districts = array();
foreach( $result as $district )
{
$districts[] = $district['districtid'];
}
return $districts;
}

function getPropertyLeasingContacts( $property_id )
{
// 1 for leasing
// 2 for building manager
$query = "
SELECT contact.*
FROM contact, property, propertycontact
WHERE property.id = $property_id
AND property.id = propertycontact.propertyid
AND contact.id = propertycontact.contactid
AND contact.contacttypeid = 1
";
$result = pgdbsql( $query, "web" );
return $result;
}

function getPropertyManager( $property_id )
{
// 1 for leasing
// 2 for building manager
$query = "
SELECT contact.*
FROM contact, property, propertycontact
WHERE property.id = $property_id
AND property.id = propertycontact.propertyid
AND contact.id = propertycontact.contactid
AND contact.contacttypeid = 2
";
$result = pgdbsql( $query, "web" );
return $result;
}

function getPropertyTag( $property_id )
{
$query = "SELECT address FROM property WHERE id = $property_id";
$result = pgdbsql( $query, "slgreenweb" );
$address = strtolower( $result[0]['address'] );
$address = join( "_", split( " ", $address ) );
$address = join( "_", split( "/", $address ) );
return $address;
}

function getPropertyPhotos( $property_id )
{
global $UPLOAD_DIR;
$property_tag = getPropertyTag( $property_id );

$pattern = '/^photo_'.$property_tag.'/';

$files = array();
$dir = opendir( $UPLOAD_DIR );
while( $f = readdir( $dir ) )
{
if( strcmp( $f, '.' ) == 0 || strcmp( $f, '..' ) == 0 ) continue;
if( preg_match( $pattern, $f ) ){
array_push( $files, $f );
}
}
closedir($dir);

return $files;
}

function getSpaces( $property_id )
{
$query = "SELECT space.*, property.* FROM space,property WHERE space.buildingid = property.id AND property.id = $property_id";
$result = pgdbsql( $query, "web" );
return $result;
}

function getSpace( $space_id )
{
$query = "
SELECT space.*, property.*, floortype.id as floortype_id, floortype.floorname as floortype_name
FROM space,property,floortype
WHERE space.buildingid = property.id
AND space.id = $space_id
AND floortype.id = space.altfloorid
";
$result = pgdbsql( $query, "web" );
return $result[0];
}

function getFloortypes()
{
$query = "SELECT id, floorname as name FROM floortype";
$result = pgdbsql( $query, "web" );
return $result;
}

function getDistricts( $sortcol = "sort_order")
{
$query = "SELECT id, districtname as name FROM district ORDER BY $sortcol";
$result = pgdbsql( $query, "web" );
return $result;
}

function getPropertiesByDistrict( $district_id )
{
$query = "
SELECT property.*
FROM property, propertydistrict
WHERE propertydistrict.districtid = $district_id
AND propertydistrict.propertyid = property.id
AND property.isactive=true
";
$result = pgdbsql( $query, "web" );
return $result;
}

?>
[/code]


above are the functions that relate to it.. mostly using getSpaces(); function.

as you can tell, it is a property search, where it searches min-max ($) in rent, min-max in sqfeet the property that is chosen and the district the property is in.
also they can sort the results using the sort form.

im always having some trouble queriying all the info out to relate to $id, so the results will read like ,  mypage.php?id=($property_id of search results)

thanks for all the help.

Share this post


Link to post
Share on other sites

×

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.