nade93 Posted June 17, 2009 Share Posted June 17, 2009 Hi All I am struggling to get the results i need from a search form i am using. my form consists of both drop down lists and checkboxes. the results are diplaying all the users rather than displaying just the users with those matching criteria this is the select method i am using $gender = $_REQUEST['gender']; $height = $_REQUEST['height']; $sexuality = $_REQUEST['sexuality']; $build = $_REQUEST['build']; $cities = $_REQUEST['cities']; $membertype = $_REQUEST['membertype']; $agegroup = $_REQUEST['agegroup']; $lookingfor = $_REQUEST['lookingfor']; $activities = $_REQUEST['activities']; SELECT DISTINCT * , GROUP_CONCAT( DISTINCT value ) FROM jos_users a JOIN jos_community_users b ON a.id = b.userid JOIN jos_community_fields_values c ON b.userid = c.user_id AND ( field_id=2 and value='$gender') OR (field_id=20 and value='$sexuality') OR (field_id=18 and value='$height') OR (field_id=19 and value='$build') OR (field_id=10 and value='$cities') OR (field_id=22 and value='$membertype') OR (field_id=21 and value='$lookingfor') OR (value = '$activities') GROUP BY a.id DESC Is there a way of just singling out the users that only have those values? thanks in advance!!! Quote Link to comment https://forums.phpfreaks.com/topic/162541-php-complex-search-form-to-search-mysql-database/ Share on other sites More sharing options...
MadTechie Posted June 17, 2009 Share Posted June 17, 2009 What table does field_id refer to ? try SELECT DISTINCT * , GROUP_CONCAT( DISTINCT value ) FROM jos_users a LEFT JOIN jos_community_users b ON a.id = b.userid LEFT JOIN jos_community_fields_values c ON b.userid = c.user_id WHERE (c.field_id=2 and c.`value`='$gender') OR (c.field_id=20 and c.`value`='$sexuality') OR (c.field_id=18 and c.`value`='$height') OR (c.field_id=19 and c.`value`='$build') OR (c.field_id=10 and c.`value`='$cities') OR (c.field_id=22 and c.`value`='$membertype') OR (field_id=21 and c.`value`='$lookingfor') OR (c.`value` = '$activities') GROUP BY a.id DESC Quote Link to comment https://forums.phpfreaks.com/topic/162541-php-complex-search-form-to-search-mysql-database/#findComment-857848 Share on other sites More sharing options...
kickstart Posted June 17, 2009 Share Posted June 17, 2009 Hi Further to the above, should the last clause ((value = '$activities')) have a check for a particular field id? If you want to keep the clauses in the ON condition then I think you also need an extra set of brackets around all the OR'ed items. All the best Keith Quote Link to comment https://forums.phpfreaks.com/topic/162541-php-complex-search-form-to-search-mysql-database/#findComment-857851 Share on other sites More sharing options...
nade93 Posted June 17, 2009 Author Share Posted June 17, 2009 hi the field_id refers to the jos_community_fields_values. in what way would you plane the on statements in the brackets? Quote Link to comment https://forums.phpfreaks.com/topic/162541-php-complex-search-form-to-search-mysql-database/#findComment-857852 Share on other sites More sharing options...
MadTechie Posted June 17, 2009 Share Posted June 17, 2009 ahh missed one field_id=21 should be c.field_id=21 also change SELECT DISTINCT * , GROUP_CONCAT( DISTINCT value ) to SELECT * Quote Link to comment https://forums.phpfreaks.com/topic/162541-php-complex-search-form-to-search-mysql-database/#findComment-857868 Share on other sites More sharing options...
nade93 Posted June 17, 2009 Author Share Posted June 17, 2009 Thanks doen both of those and it has not changed anything. thats why im stuck, done a few variations and doesnt seem to have an impact Quote Link to comment https://forums.phpfreaks.com/topic/162541-php-complex-search-form-to-search-mysql-database/#findComment-857871 Share on other sites More sharing options...
nade93 Posted June 17, 2009 Author Share Posted June 17, 2009 would some form of isset work maybe? Quote Link to comment https://forums.phpfreaks.com/topic/162541-php-complex-search-form-to-search-mysql-database/#findComment-857874 Share on other sites More sharing options...
kickstart Posted June 17, 2009 Share Posted June 17, 2009 would some form of isset work maybe? You could try something like this (excuse likely typos):- $gender = $_REQUEST['gender']; $height = $_REQUEST['height']; $sexuality = $_REQUEST['sexuality']; $build = $_REQUEST['build']; $cities = $_REQUEST['cities']; $membertype = $_REQUEST['membertype']; $agegroup = $_REQUEST['agegroup']; $lookingfor = $_REQUEST['lookingfor']; $activities = $_REQUEST['activities']; $whereClause = ""; $whereClause .= ".((isset($gender)) ? ((isset($whereClause) ? " OR " : " WHERE " )."( field_id=2 and value='$gender') " : "")." $whereClause .= ".((isset($sexuality)) ? ((isset($whereClause) ? " OR " : " WHERE " )."(field_id=20 and value='$sexuality')" : "")." $whereClause .= ".((isset($height)) ? ((isset($whereClause) ? " OR " : " WHERE " )."(field_id=18 and value='$height') " : "")." $whereClause .= ".((isset($build)) ? ((isset($whereClause) ? " OR " : " WHERE " )."(field_id=19 and value='$build') " : "")." $whereClause .= ".((isset($cities)) ? ((isset($whereClause) ? " OR " : " WHERE " )."(field_id=10 and value='$cities') " : "")." $whereClause .= ".((isset($membertype)) ((isset($whereClause) ? " OR " : " WHERE " )."(field_id=22 and value='$membertype') " : "")." $whereClause .= ".((isset($lookingfor)) ((isset($whereClause) ? " OR " : " WHERE " )."(field_id=21 and value='$lookingfor') " : "")." $whereClause .= ".((isset($activities)) ((isset($whereClause) ? " OR " : " WHERE " )."(value = '$activities') " : "")." $sql = "SELECT DISTINCT * , GROUP_CONCAT( DISTINCT value ) FROM jos_users a JOIN jos_community_users b ON a.id = b.userid JOIN jos_community_fields_values c ON b.userid = c.user_id $whereClause GROUP BY a.id DESC "; All the best Keith Quote Link to comment https://forums.phpfreaks.com/topic/162541-php-complex-search-form-to-search-mysql-database/#findComment-857954 Share on other sites More sharing options...
nade93 Posted June 17, 2009 Author Share Posted June 17, 2009 thanks keith, looks great but is bringing up and error, trying to look to see where the syntax error is but not sure Quote Link to comment https://forums.phpfreaks.com/topic/162541-php-complex-search-form-to-search-mysql-database/#findComment-857961 Share on other sites More sharing options...
kickstart Posted June 17, 2009 Share Posted June 17, 2009 Hi Probably a load of missing semi colons on the end of the lines assigning $whereClause. With those typos fixed:- $gender = $_REQUEST['gender']; $height = $_REQUEST['height']; $sexuality = $_REQUEST['sexuality']; $build = $_REQUEST['build']; $cities = $_REQUEST['cities']; $membertype = $_REQUEST['membertype']; $agegroup = $_REQUEST['agegroup']; $lookingfor = $_REQUEST['lookingfor']; $activities = $_REQUEST['activities']; $whereClause = ""; $whereClause .= ".((isset($gender)) ? ((isset($whereClause)) ? " OR " : " WHERE " )."( field_id=2 and value='$gender') " : "")." ; $whereClause .= ".((isset($sexuality)) ? ((isset($whereClause)) ? " OR " : " WHERE " )."(field_id=20 and value='$sexuality')" : "")." ; $whereClause .= ".((isset($height)) ? ((isset($whereClause)) ? " OR " : " WHERE " )."(field_id=18 and value='$height') " : "")." ; $whereClause .= ".((isset($build)) ? ((isset($whereClause)) ? " OR " : " WHERE " )."(field_id=19 and value='$build') " : "")." ; $whereClause .= ".((isset($cities)) ? ((isset($whereClause)) ? " OR " : " WHERE " )."(field_id=10 and value='$cities') " : "")." ; $whereClause .= ".((isset($membertype)) ((isset($whereClause)) ? " OR " : " WHERE " )."(field_id=22 and value='$membertype') " : "")." ; $whereClause .= ".((isset($lookingfor)) ((isset($whereClause)) ? " OR " : " WHERE " )."(field_id=21 and value='$lookingfor') " : "")." ; $whereClause .= ".((isset($activities)) ((isset($whereClause)) ? " OR " : " WHERE " )."(value = '$activities') " : "")." ; $sql = "SELECT DISTINCT * , GROUP_CONCAT( DISTINCT value ) FROM jos_users a JOIN jos_community_users b ON a.id = b.userid JOIN jos_community_fields_values c ON b.userid = c.user_id $whereClause GROUP BY a.id DESC "; All the best Keith Quote Link to comment https://forums.phpfreaks.com/topic/162541-php-complex-search-form-to-search-mysql-database/#findComment-857971 Share on other sites More sharing options...
nade93 Posted June 17, 2009 Author Share Posted June 17, 2009 sorry keith its not working still its the second whereclause. i have tried swithching colons round and still not working.... sorry Quote Link to comment https://forums.phpfreaks.com/topic/162541-php-complex-search-form-to-search-mysql-database/#findComment-857974 Share on other sites More sharing options...
kickstart Posted June 17, 2009 Share Posted June 17, 2009 Hi Sorry, load more typos:- $gender = $_REQUEST['gender']; $height = $_REQUEST['height']; $sexuality = $_REQUEST['sexuality']; $build = $_REQUEST['build']; $cities = $_REQUEST['cities']; $membertype = $_REQUEST['membertype']; $agegroup = $_REQUEST['agegroup']; $lookingfor = $_REQUEST['lookingfor']; $activities = $_REQUEST['activities']; $whereClause = ""; $whereClause .= ((empty($gender)) ? ((empty($whereClause)) ? " OR " : " WHERE " )."( field_id=2 and value='$gender') " : ""); $whereClause .= ((empty($sexuality)) ? ((empty($whereClause)) ? " OR " : " WHERE " )."(field_id=20 and value='$sexuality')" : ""); $whereClause .= ((empty($height)) ? ((empty($whereClause)) ? " OR " : " WHERE " )."(field_id=18 and value='$height') " : "") ; $whereClause .= ((empty($build)) ? ((empty($whereClause)) ? " OR " : " WHERE " )."(field_id=19 and value='$build') " : "") ; $whereClause .= ((empty($cities)) ? ((empty($whereClause)) ? " OR " : " WHERE " )."(field_id=10 and value='$cities') " : "") ; $whereClause .= ((empty($membertype)) ((empty($whereClause)) ? " OR " : " WHERE " )."(field_id=22 and value='$membertype') " : "") ; $whereClause .= ((empty($lookingfor)) ((empty($whereClause)) ? " OR " : " WHERE " )."(field_id=21 and value='$lookingfor') " : "") ; $whereClause .= ((empty($activities)) ((empty($whereClause)) ? " OR " : " WHERE " )."(value = '$activities') " : ""); $sql = "SELECT DISTINCT * , GROUP_CONCAT( DISTINCT value ) FROM jos_users a JOIN jos_community_users b ON a.id = b.userid JOIN jos_community_fields_values c ON b.userid = c.user_id $whereClause GROUP BY a.id DESC "; All the best Keith Quote Link to comment https://forums.phpfreaks.com/topic/162541-php-complex-search-form-to-search-mysql-database/#findComment-857988 Share on other sites More sharing options...
nade93 Posted June 17, 2009 Author Share Posted June 17, 2009 thanks keith i really appreciate that but its still not working, its now not returning any results at all x Quote Link to comment https://forums.phpfreaks.com/topic/162541-php-complex-search-form-to-search-mysql-database/#findComment-857996 Share on other sites More sharing options...
kickstart Posted June 17, 2009 Share Posted June 17, 2009 Hi Can you echo out the sql and see what it comes out as. All the best Keith Quote Link to comment https://forums.phpfreaks.com/topic/162541-php-complex-search-form-to-search-mysql-database/#findComment-857999 Share on other sites More sharing options...
MadTechie Posted June 17, 2009 Share Posted June 17, 2009 If your going to build your query may I suggest this way! <?php $SQL = "SELECT * FROM jos_users a LEFT JOIN jos_community_users b ON a.id = b.userid LEFT JOIN jos_community_fields_values c ON b.userid = c.user_id WHERE "; $SQL .= (empty($gender))?"":sprintf(" (c.field_id=2 and c.`value`='%s') OR",mysql_real_escape_string($gender)); $SQL .= (empty($cities))?"":sprintf(" (c.field_id=10 and c.`value`='%s') OR",mysql_real_escape_string($cities)); $SQL .= (empty($height))?"":sprintf(" (c.field_id=18 and c.`value`='%s') OR",mysql_real_escape_string($height)); $SQL .= (empty($build))?"":sprintf(" (c.field_id=19 and c.`value`='%s') OR",mysql_real_escape_string($build)); $SQL .= (empty($sexuality))?"":sprintf(" (c.field_id=20 and c.`value`='%s') OR",mysql_real_escape_string($sexuality)); $SQL .= (empty($lookingfor))?"":sprintf(" (c.field_id=21 and c.`value`='%s') OR",mysql_real_escape_string($lookingfor)); $SQL .= (empty($membertype))?"":sprintf(" (c.field_id=22 and c.`value`='%s') OR",mysql_real_escape_string($membertype)); $SQL .= (empty($activities))?"":sprintf(" (c.`value`='%s') OR",mysql_real_escape_string($activities)); $SQL = substr($SQL,0,-2); $SQL .= "GROUP BY a.id DESC " ?> Quote Link to comment https://forums.phpfreaks.com/topic/162541-php-complex-search-form-to-search-mysql-database/#findComment-858023 Share on other sites More sharing options...
kickstart Posted June 17, 2009 Share Posted June 17, 2009 If your going to build your query may I suggest this way! Very similar (and mysql_real_escape_string should definitely be used), but doesn't cope if there are no search parameters passed. All the best Keith Quote Link to comment https://forums.phpfreaks.com/topic/162541-php-complex-search-form-to-search-mysql-database/#findComment-858040 Share on other sites More sharing options...
nade93 Posted June 17, 2009 Author Share Posted June 17, 2009 hey thanks for that suggestion but this does not work either, its not returning any results. i am using this form <form action="http://www.site.com/includes/search/searchresults.php" method="post"> <table width="900" border="0" cellspacing="6" cellpadding="0"> <tr> <td><strong>Gender:</strong></td> <td><? $query="select options from jos_community_fields where id=2"; $result=mysql_query($query); // start the select box echo "<select name='gender' style='width:180px;'><option selected value=\"\"></option>\n"; while($row=mysql_fetch_assoc($result)){ echo "<option value=\"$row[options]\" >$row[options]</option>\n"; } echo "</select>"; ?></td> <td rowspan="7" valign="top"><strong>What they are into:</strong> <table width="100%" border="0" cellspacing="1" cellpadding="0"> <tr> <td>Straight sex</td> <td><? $query="select options from jos_community_fields where id=17"; $result=mysql_query($query); // start the select box while($row=mysql_fetch_row($result)){ echo "<input type=\"checkbox\" value=\"$row[options]\" >$row[options]</option>\n"; } ?></td> <td>ANY</td> <td> </td> </tr> </table></td> </tr> <tr> <td><strong>Height:</strong></td> <td><? $query2="select options from jos_community_fields where id=18"; $result=mysql_query($query2); // start the select box echo "<select name='height' style='width:180px;'><option selected value=\"pleaseselect\">Please Select</option>\n"; while($row=mysql_fetch_assoc($result)){ echo "<option value=\"$row[options]\">$row[options]</option>\n"; } echo "</select>"; ?></td> </tr> <tr> <td><strong>Sexuality:</strong></td> <td><? $query4="select options from jos_community_fields where id=20"; $result=mysql_query($query4); // start the select box echo "<select name='sexuality' style='width:180px;'><option selected value=\"pleaseselect\">Please Select</option>\n"; while($row=mysql_fetch_assoc($result)){ echo "<option value=\"$row[options]\">$row[options]</option>\n"; } echo "</select>"; ?></td> </tr> <tr> <td><strong>Build:</strong></td> <td><? $query6="select options from jos_community_fields where id=19"; $result=mysql_query($query6); // start the select box echo "<select name='build' style='width:180px;'><option selected value=\"pleaseselect\">Please Select</option>\n"; while($row=mysql_fetch_assoc($result)){ echo "<option value=\"$row[options]\">$row[options]</option>\n"; } echo "</select>"; ?></td> </tr> <tr> <td><strong>City:</strong></td> <td><? $query8="select options from jos_community_fields where id=10"; $result=mysql_query($query8); // start the select box echo "<select name='cities' style='width:180px;'><option selected value=\"pleaseselect\">Please Select</option>\n"; while($row=mysql_fetch_assoc($result)){ echo "<option value=\"$row[options]\">$row[options]</option>\n"; } echo "</select>"; ?></td> </tr> <tr> <td><strong>Membership:</strong></td> <td><? $query1="select options from jos_community_fields where id=22"; $result=mysql_query($query1); // start the select box echo "<select name='membertype' style='width:180px;'><option selected value=\"pleaseselect\">Please Select</option>\n"; while($row=mysql_fetch_assoc($result)){ echo "<option value=\"$row[options]\">$row[options]</option>\n"; } echo "</select>"; ?></td> </tr> <tr> <td><strong>Age Group:</strong></td> <td><? $query3="select options from jos_community_fields where id=23"; $result=mysql_query($query3); // start the select box echo "<select name='agegroup' style='width:180px;'><option selected value=\"pleaseselect\">Please Select</option>\n"; while($row=mysql_fetch_assoc($result)){ echo "<option value=\"$row[options]\">$row[options]</option>\n"; } echo "</select>"; ?></td> </tr> <tr> <td><strong> Looking for:</strong></td> <td><strong> <? $query5="select options from jos_community_fields where id=21"; $result=mysql_query($query5); // start the select box echo "<select name='lookingfor' style='width:180px;'><option selected value=\"pleaseselect\">Please Select</option>\n"; while($row=mysql_fetch_assoc($result)){ echo "<option value=\"$row[options]\">$row[options]</option>\n"; } echo "</select>"; ?> </strong></td> <td><label> <div align="right"> <input type="submit" name="button" id="button" value="Submit"> </div> </label></td> </tr> </table> </form> now using this search results page <? $gender = $_REQUEST['gender']; $height = $_REQUEST['height']; $sexuality = $_REQUEST['sexuality']; $build = $_REQUEST['build']; $cities = $_REQUEST['cities']; $membertype = $_REQUEST['membertype']; $agegroup = $_REQUEST['agegroup']; $lookingfor = $_REQUEST['lookingfor']; $activities = $_REQUEST['activities']; $query = "SELECT * FROM jos_users a LEFT JOIN jos_community_users b ON a.id = b.userid LEFT JOIN jos_community_fields_values c ON b.userid = c.user_id WHERE "; $query .= (empty($gender))?"":sprintf(" (c.field_id=2 and c.`value`='%s') OR",mysql_real_escape_string($gender)); $query .= (empty($cities))?"":sprintf(" (c.field_id=10 and c.`value`='%s') OR",mysql_real_escape_string($cities)); $query .= (empty($height))?"":sprintf(" (c.field_id=18 and c.`value`='%s') OR",mysql_real_escape_string($height)); $query .= (empty($build))?"":sprintf(" (c.field_id=19 and c.`value`='%s') OR",mysql_real_escape_string($build)); $query .= (empty($sexuality))?"":sprintf(" (c.field_id=20 and c.`value`='%s') OR",mysql_real_escape_string($sexuality)); $query .= (empty($lookingfor))?"":sprintf(" (c.field_id=21 and c.`value`='%s') OR",mysql_real_escape_string($lookingfor)); $query .= (empty($membertype))?"":sprintf(" (c.field_id=22 and c.`value`='%s') OR",mysql_real_escape_string($membertype)); $query .= (empty($activities))?"":sprintf(" (c.`value`='%s') OR",mysql_real_escape_string($activities)); $query = substr($SQL,0,-2); $query .= "GROUP BY a.id DESC "; $result = mysql_query($query); if ($row = mysql_fetch_array($result)) { $i = 1; do { // This loop outputs each result. print" <table width=\"80%\" border=\"0\" cellspacing=\"0\" cellpadding=\"6\" style=\"border: thin solid #CCCCCC; font-family:arial, sans-serif;\"> <tr> <td colspan=\"3\" style=\"font-size:10px; color:#CC33CC; border-bottom:thin solid #CCCCCC; background:#eaeaea;\">RESULT NO:{$i}. | USER NO. ".$row['userid']."</td> </tr> <tr> <td width=\"18%\" rowspan=\"3\"><img src=\"http://www.maskerade-swingers.com/".$row['avatar']."\" width=\"100px\" height=\"100px\"></td> <td height=\"15px\" width=\"82%\" colspan=\"2\" style=\"border-bottom:thin solid #CCCCCC; color:#cc33cc; font-size:13px;\">".$row['username']." <font color=\"#CCCCCC\" style=\"font-size:11px;\">".$row['status']."</font></td> </tr> <tr> <td colspan=\"2\"></td> </tr> <tr> <td height=\"15px\" style=\"font-size:10px; color:#CC33CC; border-top:thin solid #CCCCCC; background:#eaeaea;\"><div align=\"left\"> Friends: ".$row['friendcount']." | Matching Details: ".$row['GROUP_CONCAT( DISTINCT value )']."</div></td> <td style=\"font-size:10px; color:#CC33CC; border-top:thin solid #CCCCCC; background:#eaeaea;\"><div align=\"right\"> <a href=\"http://www.maskerade-swingers.com/index.php?option=com_community&view=profile&userid=".$row['userid']."\">View Member </div></td> </tr> </table><br>\n"; // Here you can format the search results and display whatever you want about the result. $i++; } while ($row = mysql_fetch_array($result)); } else { print"<br />Your search returned no results."; }?> the results are just not coming through thanks Quote Link to comment https://forums.phpfreaks.com/topic/162541-php-complex-search-form-to-search-mysql-database/#findComment-858046 Share on other sites More sharing options...
kickstart Posted June 17, 2009 Share Posted June 17, 2009 Hi Can you echo out $query and see what it contains. All the best Keith Quote Link to comment https://forums.phpfreaks.com/topic/162541-php-complex-search-form-to-search-mysql-database/#findComment-858054 Share on other sites More sharing options...
nade93 Posted June 17, 2009 Author Share Posted June 17, 2009 echo of the query SELECT DISTINCT * , GROUP_CONCAT( DISTINCT value ) FROM jos_users a JOIN jos_community_users b ON a.id = b.userid JOIN jos_community_fields_values c ON b.userid = c.user_id AND ( field_id=2 AND value='Male') OR (field_id=20 AND value='pleaseselect') OR (field_id=18 AND value='pleaseselect') OR (field_id=19 AND value='pleaseselect') OR (field_id=10 AND value='pleaseselect') OR (field_id=22 AND value='pleaseselect') OR (field_id=23 AND value='pleaseselect') OR (field_id=21 AND value='pleaseselect') OR (field_id=17 AND value = '') GROUP BY a.id ORDER BY GROUP_CONCAT( DISTINCT value ) DESC have reverted back to my original as this is the closes i am coming to it, the results are coming up but all the search areas are coming up in most relevant option rather than the users with those specific qualities. Quote Link to comment https://forums.phpfreaks.com/topic/162541-php-complex-search-form-to-search-mysql-database/#findComment-858059 Share on other sites More sharing options...
kickstart Posted June 17, 2009 Share Posted June 17, 2009 Hi Problem with your original solution is the precedence of AND and OR. If you want to do it that way, at the VERY least you need some extra brackets:- SELECT DISTINCT * , GROUP_CONCAT( DISTINCT value ) FROM jos_users a JOIN jos_community_users b ON a.id = b.userid JOIN jos_community_fields_values c ON b.userid = c.user_id AND (( field_id=2 AND value='Male') OR (field_id=20 AND value='pleaseselect') OR (field_id=18 AND value='pleaseselect') OR (field_id=19 AND value='pleaseselect') OR (field_id=10 AND value='pleaseselect') OR (field_id=22 AND value='pleaseselect') OR (field_id=23 AND value='pleaseselect') OR (field_id=21 AND value='pleaseselect') OR (field_id=17 AND value = '')) GROUP BY a.id ORDER BY GROUP_CONCAT( DISTINCT value ) DESC Without those the JOIN is likely to bring back very strange results (basically the JOIN condition on userid / user_id would be ignored most of the time). This is one reason to move the checks against the values into a WHERE clause. All the best Keith Quote Link to comment https://forums.phpfreaks.com/topic/162541-php-complex-search-form-to-search-mysql-database/#findComment-858062 Share on other sites More sharing options...
MadTechie Posted June 17, 2009 Share Posted June 17, 2009 Humm kinda confused as your echo doesn't match the posted code! <?php $query = "SELECT * FROM jos_users a LEFT JOIN jos_community_users b ON a.id = b.userid LEFT JOIN jos_community_fields_values c ON b.userid = c.user_id "; $where = ""; $where .= (empty($gender))?"":sprintf(" (c.field_id=2 and c.`value`='%s') OR",mysql_real_escape_string($gender)); $where .= (empty($cities))?"":sprintf(" (c.field_id=10 and c.`value`='%s') OR",mysql_real_escape_string($cities)); $where .= (empty($height))?"":sprintf(" (c.field_id=18 and c.`value`='%s') OR",mysql_real_escape_string($height)); $where .= (empty($build))?"":sprintf(" (c.field_id=19 and c.`value`='%s') OR",mysql_real_escape_string($build)); $where .= (empty($sexuality))?"":sprintf(" (c.field_id=20 and c.`value`='%s') OR",mysql_real_escape_string($sexuality)); $where .= (empty($lookingfor))?"":sprintf(" (c.field_id=21 and c.`value`='%s') OR",mysql_real_escape_string($lookingfor)); $where .= (empty($membertype))?"":sprintf(" (c.field_id=22 and c.`value`='%s') OR",mysql_real_escape_string($membertype)); $where .= (empty($activities))?"":sprintf(" (c.`value`='%s') OR",mysql_real_escape_string($activities)); $query .= (!empty($where))?"WHERE ".substr($where,0,-2):""; $query .= "GROUP BY a.id DESC "; $result = mysql_query($query) or die($query.mysql_error()); ?> Quote Link to comment https://forums.phpfreaks.com/topic/162541-php-complex-search-form-to-search-mysql-database/#findComment-858083 Share on other sites More sharing options...
nade93 Posted June 17, 2009 Author Share Posted June 17, 2009 have reverted back to my original as this is the closes i am coming to it, the results are coming up but all the search areas are coming up in most relevant option rather than the users with those specific qualities. hey reverted back as it was the only thing coming close. the suggestions were not returning any results at all Quote Link to comment https://forums.phpfreaks.com/topic/162541-php-complex-search-form-to-search-mysql-database/#findComment-858101 Share on other sites More sharing options...
kickstart Posted June 17, 2009 Share Posted June 17, 2009 hey reverted back as it was the only thing coming close. the suggestions were not returning any results at all That is why I asked about the SQL it generated. If we can see that then we stand a better chance of identifying the problem. Your original has at least an issue with the brackets. All the best Keith Quote Link to comment https://forums.phpfreaks.com/topic/162541-php-complex-search-form-to-search-mysql-database/#findComment-858108 Share on other sites More sharing options...
nade93 Posted June 17, 2009 Author Share Posted June 17, 2009 ah sorry i get you SELECT * FROM jos_users a LEFT JOIN jos_community_users b ON a.id = b.userid LEFT JOIN jos_community_fields_values c ON b.userid = c.user_id WHERE (c.field_id=2 and c.`value`='Male') OR (c.field_id=10 and c.`value`='pleaseselect') OR (c.field_id=18 and c.`value`='5ft-5ft5') OR (c.field_id=19 and c.`value`='Athletic') OR (c.field_id=20 and c.`value`='pleaseselect') OR (c.field_id=21 and c.`value`='pleaseselect') OR (c.field_id=22 and c.`value`='pleaseselect') GROUP BY a.id DESC its showing results but not defining them by the selected criteria Quote Link to comment https://forums.phpfreaks.com/topic/162541-php-complex-search-form-to-search-mysql-database/#findComment-858115 Share on other sites More sharing options...
kickstart Posted June 17, 2009 Share Posted June 17, 2009 Hi Nothing I can see majory wrong, although having a DESC on a GROUP BY isn't right. Can you get rid of the GROUP BY (not needed at this moment) and post a couple of example rows. All the best Keith Quote Link to comment https://forums.phpfreaks.com/topic/162541-php-complex-search-form-to-search-mysql-database/#findComment-858270 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.