awd2004
asked on
PHP MYSQL Advanced search code problem - dynamic form and checkboxes
I have a php page which has a form on it, on the form there is checkboxes which are drawn dynamically from a database.
The Code for the check boxes is
<?php
while (!$RsPropertyFeatures->EOF ) { // horizontal looper
?>
<td><table width="100" border="0" cellpadding="0" cellspacing="0">
<tr>
<td><table width="200" border="0" cellspacing="2" cellpadding="2">
<tr>
<td width="36"><img src="PortfolioFiles/Proper tyFeatures /<?php echo $RsPropertyFeatures->Field s('PicFile '); ?>"> </td>
<td width="124"><?php echo $RsPropertyFeatures->Field s('Propert yFeatureRe f'); ?></td>
<td width="20"><input name="propertyfeature" type="checkbox" id="propertyfeature" value="checkbox"></td>
</tr>
</table></td>
<?php
?>
</tr>
</table></td>
<?php
$RsPropertyFeatures->MoveN ext();
if (!isset($nested_RsProperty Features)) {
$nested_RsPropertyFeatures = 1;
}
if (!$RsPropertyFeatures->EOF && $nested_RsPropertyFeatures ++%2==0) {
echo "</tr><tr>";
}
//end horizontal looper
}
?>
Now I have a search function which constructs a mysql query for the options that are chosen on the html form.
This is the function so far
<?php
//Connection statement
require_once('../Connectio ns/RondaCo nnections. php');
// begin Recordset
$query_RsProperties = "SELECT * FROM rcproperty LEFT OUTER JOIN rctowns ON (rcproperty.Location = rctowns.idLocation) LEFT OUTER JOIN rclocale ON (rcproperty.Locale = rclocale.idLocale) WHERE rcproperty.idAccount = 6";
$RsProperties = $RondaConnections->SelectL imit($quer y_RsProper ties) or die($RondaConnections->Err orMsg());
$totalRows_RsProperties = $RsProperties->RecordCount ();
// end Recordset
//PHP ADODB document - made with PHAkt 2.7.3?>
<?php
//Declare Form Variables
$Ref=$_POST['Ref'];
$HouseType=$_POST['Propert yType'];
$Region=$_POST['Region'];
$Town=$_POST['Town'];
//$LPrice=$_POST['LPrice'] ;
//$HPrice=$_POST['HPrice'] ;
$Bedrooms=$_POST['Bedrooms '];
$Bathrooms=$_POST['Bathroo ms'];
$Locale=$_POST['Locale'];
// SQL Query
$SQLQUERY = " ";
// Declare optional SQL Statement
// Ref No
if ($Ref != "") {
$SQLQUERY .= "AND RefNo = '$Ref'";
}
// Property Type
if ( !empty($HouseType) && $HouseType == 'all' ) {
;
}
else {
$SQLQUERY .= "AND rcproperty.idPropertyType = '$HouseType'";
}
// Region
if ( !empty($Region) && $Region == 'all' ) {
;
}
else {
$SQLQUERY .= "AND Location = '$Region'";
}
// Town
if ( !empty($Town) && $Town == 'all' ) {
;
}
else {
$SQLQUERY .= "AND TownName = '$Town'";
}
// Bedrooms
if ( !empty($Bedrooms) && $Bedrooms == 'all' ) {
;
}
else {
$SQLQUERY .= "AND rcproperty.Bedrooms = '$Bedrooms'";
}
// Bathrooms
if ( !empty($Bathrooms) && $Bathrooms == 'all' ) {
;
}
else {
$SQLQUERY .= "AND Bathrooms = '$Bathrooms'";
}
// Locale
if ( !empty($Locale) && $Locale == 'all' ) {
;
}
else {
$SQLQUERY .= "AND Locale = '$Locale'";
}
// Store Results in Variable
$result = mysql_query($query_RsPrope rties . $SQLQUERY) or die(mysql_error() . " - $query_RsProperties" . $SQLQUERY);
?>
<?php while($row = mysql_fetch_assoc($result) ) {
echo "" .$row['PropertyName']. "" . "<BR>";
}
?>
Which works Fine as far as the drop down boxes and text fields are concerned.
Now the problem is the checkboxes. the checkboxes are property features which are drawn from another table in the database. The propertytofeatures table has this structure
CREATE TABLE `rcpropertytofeatures` (
`idPropertyToFeature` tinyint(1) NOT NULL auto_increment,
`IdProperty` tinyint(4) default NULL,
`idPropertyFeature` tinyint(4) default NULL,
PRIMARY KEY (`idPropertyToFeature`),
UNIQUE KEY `idPropertyToFeature` (`idPropertyToFeature`)
) TYPE=MyISAM
and related to that table is is the actual propertfeatures table which has this structure
CREATE TABLE `rcpropertyfeatures` (
`idPropertyFeature` int(1) NOT NULL auto_increment,
`PropertyFeatureRef` varchar(32) default NULL,
`idAccount` int(11) default NULL,
`Description` varchar(128) default NULL,
`PicFile` varchar(100) default NULL,
`idLanguage` tinyint(4) default NULL,
PRIMARY KEY (`idPropertyFeature`),
UNIQUE KEY `idPropertyFeatures` (`idPropertyFeature`),
UNIQUE KEY `idPropertyFeature` (`idPropertyFeature`),
KEY `idProperty` (`idAccount`)
) TYPE=MyISAM
Now what i need to do (I think) Is query the $result again to find out which properties have which property features if they have selected any of them.
How do i do this????
ps this was the original question I asked before i realised it wouldnt work!!!
https://www.experts-exchange.com/questions/21143846/Search-Function-with-PHP-Checkboxes-Question.html
The Code for the check boxes is
<?php
while (!$RsPropertyFeatures->EOF
?>
<td><table width="100" border="0" cellpadding="0" cellspacing="0">
<tr>
<td><table width="200" border="0" cellspacing="2" cellpadding="2">
<tr>
<td width="36"><img src="PortfolioFiles/Proper
<td width="124"><?php echo $RsPropertyFeatures->Field
<td width="20"><input name="propertyfeature" type="checkbox" id="propertyfeature" value="checkbox"></td>
</tr>
</table></td>
<?php
?>
</tr>
</table></td>
<?php
$RsPropertyFeatures->MoveN
if (!isset($nested_RsProperty
$nested_RsPropertyFeatures
}
if (!$RsPropertyFeatures->EOF
echo "</tr><tr>";
}
//end horizontal looper
}
?>
Now I have a search function which constructs a mysql query for the options that are chosen on the html form.
This is the function so far
<?php
//Connection statement
require_once('../Connectio
// begin Recordset
$query_RsProperties = "SELECT * FROM rcproperty LEFT OUTER JOIN rctowns ON (rcproperty.Location = rctowns.idLocation) LEFT OUTER JOIN rclocale ON (rcproperty.Locale = rclocale.idLocale) WHERE rcproperty.idAccount = 6";
$RsProperties = $RondaConnections->SelectL
$totalRows_RsProperties = $RsProperties->RecordCount
// end Recordset
//PHP ADODB document - made with PHAkt 2.7.3?>
<?php
//Declare Form Variables
$Ref=$_POST['Ref'];
$HouseType=$_POST['Propert
$Region=$_POST['Region'];
$Town=$_POST['Town'];
//$LPrice=$_POST['LPrice']
//$HPrice=$_POST['HPrice']
$Bedrooms=$_POST['Bedrooms
$Bathrooms=$_POST['Bathroo
$Locale=$_POST['Locale'];
// SQL Query
$SQLQUERY = " ";
// Declare optional SQL Statement
// Ref No
if ($Ref != "") {
$SQLQUERY .= "AND RefNo = '$Ref'";
}
// Property Type
if ( !empty($HouseType) && $HouseType == 'all' ) {
;
}
else {
$SQLQUERY .= "AND rcproperty.idPropertyType = '$HouseType'";
}
// Region
if ( !empty($Region) && $Region == 'all' ) {
;
}
else {
$SQLQUERY .= "AND Location = '$Region'";
}
// Town
if ( !empty($Town) && $Town == 'all' ) {
;
}
else {
$SQLQUERY .= "AND TownName = '$Town'";
}
// Bedrooms
if ( !empty($Bedrooms) && $Bedrooms == 'all' ) {
;
}
else {
$SQLQUERY .= "AND rcproperty.Bedrooms = '$Bedrooms'";
}
// Bathrooms
if ( !empty($Bathrooms) && $Bathrooms == 'all' ) {
;
}
else {
$SQLQUERY .= "AND Bathrooms = '$Bathrooms'";
}
// Locale
if ( !empty($Locale) && $Locale == 'all' ) {
;
}
else {
$SQLQUERY .= "AND Locale = '$Locale'";
}
// Store Results in Variable
$result = mysql_query($query_RsPrope
?>
<?php while($row = mysql_fetch_assoc($result)
echo "" .$row['PropertyName']. "" . "<BR>";
}
?>
Which works Fine as far as the drop down boxes and text fields are concerned.
Now the problem is the checkboxes. the checkboxes are property features which are drawn from another table in the database. The propertytofeatures table has this structure
CREATE TABLE `rcpropertytofeatures` (
`idPropertyToFeature` tinyint(1) NOT NULL auto_increment,
`IdProperty` tinyint(4) default NULL,
`idPropertyFeature` tinyint(4) default NULL,
PRIMARY KEY (`idPropertyToFeature`),
UNIQUE KEY `idPropertyToFeature` (`idPropertyToFeature`)
) TYPE=MyISAM
and related to that table is is the actual propertfeatures table which has this structure
CREATE TABLE `rcpropertyfeatures` (
`idPropertyFeature` int(1) NOT NULL auto_increment,
`PropertyFeatureRef` varchar(32) default NULL,
`idAccount` int(11) default NULL,
`Description` varchar(128) default NULL,
`PicFile` varchar(100) default NULL,
`idLanguage` tinyint(4) default NULL,
PRIMARY KEY (`idPropertyFeature`),
UNIQUE KEY `idPropertyFeatures` (`idPropertyFeature`),
UNIQUE KEY `idPropertyFeature` (`idPropertyFeature`),
KEY `idProperty` (`idAccount`)
) TYPE=MyISAM
Now what i need to do (I think) Is query the $result again to find out which properties have which property features if they have selected any of them.
How do i do this????
ps this was the original question I asked before i realised it wouldnt work!!!
https://www.experts-exchange.com/questions/21143846/Search-Function-with-PHP-Checkboxes-Question.html
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
I agree
Mike