shoaib
11-10-2010, 07:34 AM
Hi,
I am using a Search form. Where I have Multiple elements if I select any of the value and click the Search button the Related data should be displayed.
For clear idea see the attachment.
I used the Mysql Query Where condition like this.
WHERE `brideorgroom` = '$lookingfor' OR `city` = '$city' OR `state` = '$state' OR `occupation` = '$occupation' OR `age` >= '$age' AND `age` <= '$toage'
But this is not working good when i select more than one element for search.
Please provide me a better solution.
Regards,
Shoaib.:)
abduraooft
11-10-2010, 07:53 AM
But this is not working good when i select more than one element for search.
Please post your complete code. Also echo your query to make sure that the variables are getting correctly substituted there.
shoaib
11-10-2010, 08:41 AM
Hi,
I am using this form in Chronoconnectivity component in joomla.
The HTML Coding is
<html>
<head>
<title>Advance Search</title>
</head>
<body>
<div style="margin-top:10px;">
<table>
<tbody>
<tr>
<td>
Looking For :
</td>
<td>
<input type="radio" name="lookingfor" value="Groom" /> Groom
<input type="radio" name="lookingfor" value="Bride" /> Bride
</td>
</tr>
</div>
<tr>
<td>
<div style="margin-top:10px;">
Age in Years : </td><td>
<select name="age">
<option value="0">Select</option>
<option value="18">18</option>
<option value="19">19</option>
<option value="20">20</option>
<option value="21">21</option>
</select>
to
<select name="toage">
<option value="0">Select</option>
<option value="18">18</option>
<option value="19">19</option>
<option value="20">20</option>
<option value="21">21</option>
</select>
</div>
<div>
</td>
</tr>
</div>
<div style="margin-top:10px;">
<tr>
<td>
Marital Status:</td><td>
<input type="radio" name="maritalstatus" value="Single" /> Single
<input type="radio" name="maritalstatus" value="Divorced" /> Divorced
<input type="radio" name="maritalstatus" value="Seperated" /> Seperated
</td>
<tr>
</div>
<div> </div>
</br> </br>
<div style="margin-top:10px;">
<tr>
<td>
Looks:</td><td>
<select name="looks">
<option value="0">Select</option>
<option value="Slim">Slim</option>
<option value="Average">Average</option>
<option value="Not too Fat">Not too Fat</option>
<option value="Fat">Fat</option>
</select>
</td>
</tr>
</div>
<div> </div>
<div style="margin-top:10px;">
<tr>
<td>
Mother Tongue:</td>
<td>
<input type="radio" name="mothertongue" value="Tamil" /> Tamil
<input type="radio" name="mothertongue" value="Telugu" /> Telugu
<input type="radio" name="mothertongue" value="Kannada" /> Kannada
<input type="radio" name="mothertongue" value="English" /> English
</td>
</tr>
</div>
<div style="margin-top:10px;">
<tr>
<td>
Education:</td><td>
<select name="education">
<option value="0">Select</option>
<option value="No Education">No Education</option>
<option value="High School">High School</option>
<option value="Under Graduate">Under Graduate</option>
<option value="Graduate">Graduate</option>
<option value="Post Graduate">Post Graduate</option>
</select>
</td>
</tr>
</div>
<div style="margin-top:10px;">
<tr>
<td>
Occupation</td><td>
<select name="occupation">
<option value="0">Select</option>
<option value="Self Employed">Self Employed</option>
<option value="Business">Business</option>
<option value="Corporate">Corporate</option>
<option value="Government">Government</option>
<option value="Un Employed">Un Employed</option>
<option value="Profession">Profession</option>
</select>
</td>
</tr>
</div>
<div style="margin-top:10px;margin-bottom:20px;">
<tr>
<td ></td>
<td>
<input type="submit" value="Search" height = "20px" width= "40px" />
</td>
</tr>
<tr>
<td>
<div>
</div>
</td>
</tr>
</tbody>
</table>
</div>
</div>
</body>
</html>
This is the value displaying echo page coding.
<?php
echo "<table width=800 border=0 style ='background-color:#EDEBE7;'>\n";
print "<tr>\n";
echo " <td style='font-weight:bold;font-size:12px;vertical-align:top;font-family:Arial,Helvetica,sans-serif;'> {profilename}</h6><br><img src={profilephoto} height='100px' width='100px'></img> </td>";
echo " <td style='width:400px;vertical-align:top;text-align:justify;'><b>About Myself: </b><br> {about_myself} </td>";
echo " <td style='vertical-align:top;'><b>Age: </b> {age}
<br><b>Education: </b> {education}
<br><b>Occupation: </b> {occupation}
<br><b>Annual Income: </b> {annual_income}
<br><b>Martial Status: </b> {martial_status}
</td>";
print "</tr>";
print "<tr>\n";
echo " <td></td>";
echo " <td></td>";
echo " <td ><a href=index.php?option=com_chronocontact&chronoformname=detailview&vname={id} style ='float:right;'><input type='submit' value='More Info' /> </a></td>";
print "</tr>";
echo "</table>\n";
echo "<br>";
?>
And the MySql Where condition page code is
<?php
$lookingfor = JRequest::getVar('lookingfor', '', 'post');
$age = JRequest::getVar('age', '', 'post');
$toage = JRequest::getVar('toage', '', 'post');
$maritalstatus = JRequest::getVar('maritalstatus', '', 'post');
$looks = JRequest::getVar('looks', '', 'post');
$mothertongue = JRequest::getVar('mothertongue', '', 'post');
$education = JRequest::getVar('education', '', 'post');
$occupation = JRequest::getVar('occupation', '', 'post');
if ($lookingfor == 'null' && $age == 0 && $toage == 0 && $maritalstatus == 'null' && $looks == 0 && $mothertongue == 'null' && $education == 0 && $occupation == 0 )
{
echo "WHERE `brideorgroom`= 'dfgjkfdlg' ";
}
else
{
echo "WHERE `brideorgroom` = '$lookingfor' OR `martial_status` = '$maritalstatus' OR `looks` = '$looks' OR `mother_tongue` = '$mothertongue' OR `education` = '$education' OR `occupation` = '$occupation' OR `age` >= '$age' AND `age` <= '$toage'";
}
?>
See the attachment
Now if I select the Looking For : as Groom click search button I get the All the Groom data Correctly
If I select the Looking For : as Groom and Marital Status: as Single and click search
I get the All the Groom and All the data with marital status with single even from the Bride.
How will i check if more than one search is selected and how will i query for it?
Regards,
Osmodels.:)
shoaib
11-13-2010, 06:45 AM
Friendly bump....
Regards,
Shoaib.
:)
abduraooft
11-13-2010, 07:15 AM
Also echo your query to make sure that the variables are getting correctly substituted there. Where's your final complete query?
shoaib
11-16-2010, 06:33 AM
Hi,
Here in Chronoform we dont need to write the whole query.
if ($lookingfor == 'null' && $age == 0 && $toage == 0 && $maritalstatus == 'null' && $looks == 0 && $mothertongue == 'null' && $education == 0 && $occupation == 0 )
{
echo "WHERE `brideorgroom`= 'dfgjkfdlg' ";
}
else
{
echo "WHERE `brideorgroom` = '$lookingfor' OR `martial_status` = '$maritalstatus' OR `looks` = '$looks' OR `mother_tongue` = '$mothertongue' OR `education` = '$education' OR `occupation` = '$occupation' OR `age` >= '$age' AND `age` <= '$toage'";
}
This echo Where Condition Does its job.
I dont have any bugs in this if I select any one field and search for it. It gives me the correct records.
But if I select more than one Field for Search It does not gives me the correct search result.
My question how should I write the code for More than one field is selected.
As I have 8 Fields in Search it gives me 8*7*6*5*4*3*2*1 Probility of search. Should I write "IF" Condition For All Or Is there Any Short Method For Selecting only the "Filled Field ( Which is not empty)" And Search With it.
Regards,
Shoaib