i did post this before but didnt have any luck I have used my search script before but tried it again and it is returning ALL the results from the DB..Can anyone see what i am missing?
$var_SalaryReq_Recordset1 = "%";
if (isset($_GET['SalaryReq'])) {
$var_SalaryReq_Recordset1 = $_GET['SalaryReq'];
}
$var_skills_offered_Recordset1 = "%";
if (isset($_GET['skills_offered'])) {
$var_skills_offered_Recordset1 = $_GET['skills_offered'];
}
$var_location_Recordset1 = "%";
if (isset($_GET['location'])) {
$var_location_Recordset1 = $_GET['location'];
}
$var_PositionReq_Recordset1 = "%";
if (isset($_GET['PositionReg'])) {
$var_PositionReq_Recordset1 = $_GET['PositionReg'];
}
mysql_select_db($database_hostprop, $hostprop);
$query_Recordset1 = sprintf("SELECT userid, FirstName, Surname, SalaryReq, PositionReq, location, otherComments, skills_offered FROM think_signup WHERE SalaryReq LIKE %s OR PositionReq LIKE %s OR location LIKE %s OR skills_offered LIKE %s", GetSQLValueString("%" . $var_SalaryReq_Recordset1 . "%", "text"),GetSQLValueString("%" . $var_PositionReq_Recordset1 . "%", "text"),GetSQLValueString("%" . $var_location_Recordset1 . "%", "text"),GetSQLValueString("%" . $var_skills_offered_Recordset1, "text"));
$query_limit_Recordset1 = sprintf("%s LIMIT %d, %d", $query_Recordset1, $startRow_Recordset1, $maxRows_Recordset1);
$Recordset1 = mysql_query($query_limit_Recordset1, $hostprop) or die(mysql_error());
$row_Recordset1 = mysql_fetch_assoc($Recordset1);
the search feilds are
<input name="PositionReq" type="text" class="textfeilds" value="Job Title" size="32" />
<input name="skills_offered" type="text" class="textfeilds" value="Skills Required" size="32" />
<input name="SalaryReq" type="text" class="textfeilds" value="Salary Offered" size="32" />
<input name="location" type="text" class="textfeilds" value="Location" size="32" />
thanks in advance
>SELECT userid, FirstName, Surname, SalaryReq, PositionReq, location, otherComments, skills_offered FROM think_signup
>WHERE SalaryReq LIKE %s OR PositionReq LIKE %s OR location LIKE %s OR skills_offered LIKE %s
That query will only work if the user enters values in all fields, right? Otherwise it will return all rows. How are you testing this?
You could not have used the same logic successfully before - it simply will not work. You are using the LIKE predicate and OR keywords separating your conditions. And you are setting the default value to the SQL wildcard. So if a user doesn't enter a value in a field, all rows from the table will match.
As I have said before, the best way to solve this is to dynamically build the WHERE clause. You add each field to the WHERE clause only if the user entered a value. Another option, and a bit of a kludge in my option, is to set the default value to something that you know will never appear in the table values, like "XXXXXXX".
Also, not related to your problem, but I notice that your skills_offered field is not appending the wildcard to the end. Not sure if this was intentional.
this is the statment from the previous search that works how i need it
$var_tk_job_title_Recordset1 = "%";
if (isset($_GET["tk_job_title"])) {
$var_tk_job_title_Recordset1 = $_GET["tk_job_title"];
}
$var_tk_job_location_Recordset1 = "%";
if (isset($_GET["tk_job_location"])) {
$var_tk_job_location_Recordset1 = $_GET["tk_job_location"];
}
$var_tk_job_salary_Recordset1 = "%";
if (isset($_GET["tk_job_salary"])) {
$var_tk_job_salary_Recordset1 = $_GET["tk_job_salary"];
}
mysql_select_db($database_hostprop, $hostprop);
$query_Recordset1 = sprintf("SELECT tk_job_title, tk_job_location, tk_job_salary, LEFT(tk_job_desc,200) as truncated_job_desc FROM think_jobsearch WHERE tk_job_title LIKE %s OR tk_job_location LIKE %s OR tk_job_salary LIKE %s", GetSQLValueString("%" . $var_tk_job_title_Recordset1 . "%", "text"),GetSQLValueString("%" . $var_tk_job_location_Recordset1 . "%", "text"),GetSQLValueString("%" . $var_tk_job_salary_Recordset1 . "%", "text"));
$query_limit_Recordset1 = sprintf("%s LIMIT %d, %d", $query_Recordset1, $startRow_Recordset1, $maxRows_Recordset1);
$Recordset1 = mysql_query($query_limit_Recordset1, $hostprop) or die(mysql_error());
$row_Recordset1 = mysql_fetch_assoc($Recordset1);
and thats why i replicated it for the new search
>As I have said before, the best way to solve this is to dynamically build the WHERE clause. You add each field to the WHERE clause only if the user entered a value.
was this in a previous post?
.>Also, not related to your problem, but I notice that your skills_offered field is not appending the wildcard to the end. Not sure if this was intentional
no this was not intentional, i have amended this
$currentPage = $_SERVER["PHP_SELF"];
$maxRows_Recordset1 = 5;
$pageNum_Recordset1 = 0;
if (isset($_GET['pageNum_Recordset1'])) {
$pageNum_Recordset1 = $_GET['pageNum_Recordset1'];
}
$startRow_Recordset1 = $pageNum_Recordset1 * $maxRows_Recordset1;
$var_SalaryReq_Recordset1 = "xxxxx";
if (isset($_GET['SalaryReq'])) {
$var_SalaryReq_Recordset1 = $_GET['SalaryReq'];
}
$var_skills_offered_Recordset1 = "xxxxx";
if (isset($_GET['skills_offered'])) {
$var_skills_offered_Recordset1 = $_GET['skills_offered'];
}
$var_location_Recordset1 = "xxxxx";
if (isset($_GET['location'])) {
$var_location_Recordset1 = $_GET['location'];
}
$var_PositionReq_Recordset1 = "xxxxx";
if (isset($_GET['PositionReg'])) {
$var_PositionReq_Recordset1 = $_GET['PositionReg'];
}
mysql_select_db($database_hostprop, $hostprop);
$query_Recordset1 = sprintf("SELECT SalaryReq, skills_offered, location, PositionReq, otherComments, userid, FirstName, Surname FROM think_signup WHERE SalaryReq LIKE %s OR PositionReq LIKE %s OR location LIKE %s OR skills_offered LIKE %s", GetSQLValueString("%" . $var_SalaryReq_Recordset1 . "%", "text"),GetSQLValueString("%" . $var_skills_offered_Recordset1 . "%", "text"),GetSQLValueString("%" . $var_location_Recordset1 . "%", "text"),GetSQLValueString("%" . $var_PositionReq_Recordset1 . "%", "text"));
$query_limit_Recordset1 = sprintf("%s LIMIT %d, %d", $query_Recordset1, $startRow_Recordset1, $maxRows_Recordset1);
$Recordset1 = mysql_query($query_limit_Recordset1, $hostprop) or die(mysql_error());
$row_Recordset1 = mysql_fetch_assoc($Recordset1);
if (isset($_GET['totalRows_Recordset1'])) {
$totalRows_Recordset1 = $_GET['totalRows_Recordset1'];
} else {
$all_Recordset1 = mysql_query($query_Recordset1);
$totalRows_Recordset1 = mysql_num_rows($all_Recordset1);
}
$totalPages_Recordset1 = ceil($totalRows_Recordset1/$maxRows_Recordset1)-1;
$queryString_Recordset1 = "";
if (!empty($_SERVER['QUERY_STRING'])) {
$params = explode("&", $_SERVER['QUERY_STRING']);
$newParams = array();
foreach ($params as $param) {
if (stristr($param, "pageNum_Recordset1") == false &&
stristr($param, "totalRows_Recordset1") == false) {
array_push($newParams, $param);
}
}
if (count($newParams) != 0) {
$queryString_Recordset1 = "&" . htmlentities(implode("&", $newParams));
}
}
$queryString_Recordset1 = sprintf("&totalRows_Recordset1=%d%s", $totalRows_Recordset1, $queryString_Recordset1);
the form is
<input name="PositionReq" type="text" class="textfeilds" value="Job Title" size="32" />
<input name="skills_offered" type="text" class="textfeilds" value="Skills Required" size="32" />
<input name="SalaryReq" type="text" class="textfeilds" value="Salary Offered" size="32" />
<input name="location" type="text" class="textfeilds" value="Location" size="32" />
examples of search criteria are job title would be say police officer, location would be say london
when using xxxx no results are being dispalyed
<form id="form3" name="form3" method="post" action="../candidate-search-results.php">
<p>
<input name="PositionReq" type="text" class="textfeilds" value="Job Title" size="32" />
<input name="skills_offered" type="text" class="textfeilds" value="Skills Required" size="32" />
<input name="SalaryReq" type="text" class="textfeilds" value="Salary Offered" size="32" />
<input name="location" type="text" class="textfeilds" value="Location" size="32" />
<td colspan="2"><img name="CANDSEARCH_r1_c1_s1" src="../images/CANDSEARCH_r1_c1_s1.png" width="74" height="5" border="0" id="CANDSEARCH_r1_c1_s1" alt="" /></td>
<td rowspan="3"><a href="../candidate-search-results.php" onmouseout="MM_nbGroup('out');" onmouseover="MM_nbGroup('over','CANDSEARCH_r1_c3_s1','images/CANDSEAR CH_r1_c3_s2.png','images/CANDSEARCH_r1_c3_s4.png',1);" onclick="MM_nbGroup('down','navbar1','CANDSEARCH_r1_c3_s1','images/CA NDSEARCH_r1_c3_s3.png',1);">
<input type="image" src="../images/CANDSEARCH_r1_c3_s1.png" width="50" height="17" border="0" id="CANDSEARCH_r1_c3_s1" alt="" />
</form>
OK,i see that when i posted to the thread, i have now changed the form to GET but it is still not working, if i change the default value to the wildcard % it displays all the results but if i change it to xxxxx i get no results, so i know the way the form was sent was incorrect but now being changed i am still getting the same results.
i put an echo at the end of the script, i then done a search on the location and the echo gave the following resutls
SELECT SalaryReq, skills_offered, location, PositionReq, otherComments, userid, FirstName, Surname FROM think_signup WHERE SalaryReq LIKE '%%%' OR PositionReq LIKE '%%%' OR location LIKE '%%%' OR skills_offered LIKE '%%%'
><input name="location" type="text" class="textfeilds" value="Location" size="32" />
Why are you populating a value in the text field? How are you clearning that out before submitting?
>SELECT SalaryReq, skills_offered, location, PositionReq, otherComments, userid, FirstName,
>Surname FROM think_signup WHERE SalaryReq LIKE '%%%' OR PositionReq LIKE '%%%'
>OR location LIKE '%%%' OR skills_offered LIKE '%%%'
This tells me that your default value is still '%' and you have NOT changed it to 'xxxxx'. Or, you are using some unposted method to populate it with '%'.
>Why are you populating a value in the text field? How are you clearning that out before submitting?
this is to show the user what to input, i am not clearing it before submission (this is the same as the other search that working)
sorry i was trying something i have changed the values back and done another echo test
SELECT SalaryReq, skills_offered, location, PositionReq, otherComments, userid, FirstName, Surname FROM think_signup WHERE SalaryReq LIKE '%xxxxx%' OR PositionReq LIKE '%xxxxx%' OR location LIKE '%xxxxx%' OR skills_offered LIKE '%xxxxx%'
Submit the form, and then copy the url from the address bar and post it here.
>this is to show the user what to input, i am not clearing it before submission (this is the same as the other search that working)
The only reason it appears to be working is because the default values you put into those fields has not yet appeared in your data. But this is obviously a very poor practice that will eventually lead to trouble. You must always clear out that data before posting.
http://www.rerecruitment.co.uk/beta/candidate-search-results.php
it isnt passing any of the information
the other search that is working is giving the following results
current-positions.php?tk_job_title=security&tk_job_location=Location&t k_job_salary=Salary&x=87&y=5
again here is the echo
SELECT SalaryReq, skills_offered, location, PositionReq, otherComments, userid, FirstName, Surname FROM think_signup WHERE SalaryReq LIKE '%xxxxx%' OR PositionReq LIKE '%xxxxx%' OR location LIKE '%xxxxx%' OR skills_offered LIKE '%xxxxx%'
>should i change the other search page to xxxx rather than the wildcard?
I can't comment without knowing all of the details. If you are using AND to combine conditions, then you probably want to continue using the wildcard. In any case, I wouldn't put default text in the form fields. Use labels to help the user complete the form.
>its strange becuase some of the feilds are working the job title isnt working
>and neither is the skills required but the salary offered and location are working now
When you are not getting the expected results, we need to see the SQL submitted - every time.
Echo the $query_Recordset1 variable and post the results.
in the db i have an input called security in the PositionReq field, then in the skills_offered i have an input called fireman in the SalaryReq feild i have a neg result and for locatio i have test 12 stored
searching for jobtitle for security
SELECT SalaryReq, skills_offered, location, PositionReq, otherComments, userid, FirstName, Surname FROM think_signup WHERE SalaryReq LIKE '%Salary Offered%' OR PositionReq LIKE '%Skills Required%' OR location LIKE '%Location%' OR skills_offered LIKE '%xxxxx%'
this has no results
this looks like something is going wrong here??
searching skills required for fireman
SELECT SalaryReq, skills_offered, location, PositionReq, otherComments, userid, FirstName, Surname FROM think_signup WHERE SalaryReq LIKE
'%Salary Offered%' OR PositionReq LIKE '%fireman%' OR location LIKE '%Location%' OR skills_offered LIKE '%xxxxx%'
this has no results
searching salary required for NEG
SELECT SalaryReq, skills_offered, location, PositionReq, otherComments, userid, FirstName, Surname FROM think_signup WHERE SalaryReq LIKE '%neg%' OR PositionReq LIKE '%Skills Required%' OR location LIKE '%Location%' OR skills_offered LIKE '%xxxxx%'
a result is displayed
searching for test 12
SELECT SalaryReq, skills_offered, location, PositionReq, otherComments, userid, FirstName, Surname FROM think_signup WHERE SalaryReq LIKE '%Salary Offered%' OR PositionReq LIKE '%Skills Required%' OR location LIKE '%test 12%' OR skills_offered LIKE '%xxxxx%'
a result is displayed
>SELECT SalaryReq, skills_offered, location, PositionReq, otherComments, userid, FirstName,
>Surname FROM think_signup WHERE SalaryReq LIKE '%Salary Offered%' OR PositionReq
>LIKE '%Skills Required%' OR location LIKE '%Location%' OR skills_offered LIKE '%xxxxx%'
>
>this has no results
Right. Are you expecting a result? You have no search criteria entered, other than the default values you have in the form fields.
>SELECT SalaryReq, skills_offered, location, PositionReq, otherComments, userid, FirstName, Surname FROM think_signup WHERE SalaryReq LIKE
>'%Salary Offered%' OR PositionReq LIKE '%fireman%' OR location LIKE '%Location%' OR skills_offered LIKE '%xxxxx%'
>
>this has no result
Right. You are searching for 'fireman' in the PositionReq column, but you stated above that it is in the skills_offered column.
Why does PositionReq SalaryReq use proper case naming, while skills_offered uses lower case with an underscore? Things are a real mess! We've already found about a dozen errors in your code for this relatively simple search form.
>Right. Are you expecting a result? You have no search criteria entered, other than the default values you have in the form fields.
i did put an input of security, i dont know why it isnt showing any results
Right. You are searching for 'fireman' in the PositionReq column, but you stated above that it is in the skills_offered column.
i see that now!, this is a mess
Why does PositionReq SalaryReq use proper case naming, while skills_offered uses lower case with an underscore? Things are a real mess! We've already found about a dozen errors in your code for this relatively simple search form.
I dont understand how it has got like this. Is is a problem ( i know its not good practice) to have an underscore
or should i go back and start again
i found the problem, i have another recordset in the main body of the page. the trouble is the other recordset needs to go throughout the site and need to be inbedded into the non editable region. it is only showing results from the DB. When i insert it into the main site it give problems to the pages that already containing infor from the DB
>Is is a problem ( i know its not good practice) to have an underscore
>or should i go back and start again
You can use underscores, proper case, camel case -anything that you want. The key is consistency; it makes your code easier to read which results in less coding errors and easier maintenance. Pick a naming convention for your objects and stick with it 100% of the time. You don't need to use the same convention for database objects as you do for php objects - but within each object type (table name, column name, local variable, etc) be consistent. Search the web for 'database naming conventions' and 'php naming conventions' for some ideas.
Hello, i am testing the search code
$var_SalaryReq_Recordset1 = "xxxxx";
if (isset($_GET['SalaryReq'])) {
$var_SalaryReq_Recordset1 = $_GET['SalaryReq'];
}
$var_skills_offered_Recordset1 = "xxxxx";
if (isset($_GET['skills_offered'])) {
$var_skills_offered_Recordset1 = $_GET['skills_offered'];
}
$var_location_Recordset1 = "xxxxx";
if (isset($_GET['location'])) {
$var_location_Recordset1 = $_GET['location'];
}
$var_PositionReq_Recordset1 = "xxxxx";
if (isset($_GET['PositionReq'])) {
$var_PositionReq_Recordset1 = $_GET['PositionReq'];
}
mysql_select_db($database_hostprop, $hostprop);
$query_Recordset1 = sprintf("SELECT userid, FirstName, Surname, SalaryReq, PositionReq, location, otherComments, skills_offered FROM think_signup WHERE SalaryReq LIKE %s OR PositionReq LIKE %s OR location LIKE %s OR skills_offered LIKE %s", GetSQLValueString("%" . $var_SalaryReq_Recordset1 . "%", "text"),GetSQLValueString("%" . $var_PositionReq_Recordset1 . "%", "text"),GetSQLValueString("%" . $var_location_Recordset1 . "%", "text"),GetSQLValueString("%" . $var_skills_offered_Recordset1, "text"));
$query_limit_Recordset1 = sprintf("%s LIMIT %d, %d", $query_Recordset1, $startRow_Recordset1, $maxRows_Recordset1);
$Recordset1 = mysql_query($query_limit_Recordset1, $hostprop) or die(mysql_error());
$row_Recordset1 = mysql_fetch_assoc($Recordset1);
in the database i have in the skills_offered column
good communicator excellent negotiator truck driver
when i search good communicator i get nothing, when i search excellent negotiator i get nothing, when i search truck driver i get tthe result. i have tried various combinations like good driver and i get nothing
can anyone help?
North America
Europe, Middle East and Africa
Asia Pacific