Forum Moderators: coopster

Message Too Old, No Replies

Search script - need help

         

adammc

5:36 am on Sep 14, 2005 (gmt 0)

10+ Year Member



Hi folks,
I have just discovered with GREAT horror that the search script that I am using on my site isnt functioning properly!

If you do a search using the keword "chef", results are returned.

However if you search for "chef jobs" nothing is returned.

On the form there is a radio button for search method. I have tried checking both of these, results are the same. Preferably I want to remove the search method option from the script.

Any help would be GREATLY appreciated :)

form page:


<tr>
<td><font size='2' face='Verdana' color='black'>Search method: </font></td>
<td><input style='BORDER-RIGHT: ffffff 1px solid; BORDER-TOP: ffffff 1px solid; FONT-SIZE: 8pt; BORDER-LEFT: ffffff 1px solid; COLOR: #FFFFFF; BORDER-BOTTOM: ffffff 1px solid' type=radio name=sm value=or>
or &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <input style='BORDER-RIGHT: ffffff 1px solid; BORDER-TOP: ffffff 1px solid; FONT-SIZE: 8pt; BORDER-LEFT: ffffff 1px solid; COLOR: #FFFFFF; BORDER-BOTTOM: ffffff 1px solid' type=radio name=sm value=and checked>
and </td>
</tr>

search results :


$sch = array();
if (!empty($position))
{
$sch[] = "position like '%$_GET[position]%'";
}
if (!empty($JobIn))
{
$sch[] = "JobIn like '%$_GET[JobIn]%' ";
}
if (!empty($JobCategory))
{
$sch[] = "JobCategory like '%$_GET[JobCategory]%' ";
}
if (!empty($employment_type))
{
$sch[] = "employment_type = '$_GET[employment_type]'";
}
if (!empty($kw))
{
$sch[] = "position like '%$_GET[kw]%' or description like '%$_GET[kw]%'";
}

if (!$ByPage) $ByPage=25;
if (!$Start) $Start=0;

if($sm == 'or')
{
$qs = "select * from job_post ".(($sch)?"where ".join(" or ", $sch):"")." limit $Start,$ByPage";
$qss = "select * from job_post ".(($sch)?"where ".join(" or ", $sch):"");
}
elseif($sm == 'and')
{
$qs = "select * from job_post ".(($sch)?"where ".join(" and ", $sch):"")." limit $Start,$ByPage";
$qss = "select * from job_post ".(($sch)?"where ".join(" and ", $sch):"");
}
$rqs = mysql_query($qs) or die(mysql_error());
$rqss = mysql_query($qss) or die(mysql_error());

$rr = mysql_num_rows($rqss);

if($rr == '0')
{
echo "<br><br><font size='2' face='Verdana' color='black'>Sorry, no results found.</font> : <a href='http://www.example.com/jobseekers/job-search.php?kw=$kw'><font font size='2' face='Verdana' color='#000099'>search again</font></a></center><br>";
}
elseif($rr == '1')
{
echo "<br><br><center><b> $SRONE. </b></center>";
}
elseif($rr > '1')
{
echo "<br><b><font size='1' face='Verdana' color='black'>Your search returned <font font size='2' face='Verdana' color='#000099'>$rr</font> results. </b></font></center>";
}

$col = "cococo";

echo "<br><table width=100% align=center cellpadding='3' cellspacing=1>
<tr bgcolor=$s2>
<td><font size='2' face='Verdana' color='white'><b>Position:</b></font> </td><td><b><font size='2' face='Verdana' color='white'>$JOBCATEGORY</b></font> </td><td width=85><center><b><font size='2' face='Verdana' color='white'>Expires in:</b></font></center></td></tr>";

while($as = mysql_fetch_array($rqs))
{
//$ex13 = date('d', mktime(0,0,0, $as[EXmonth] - date(m), $as[EXday] - date(d), $as[EXyear] - date(Y)));

$day = date(d);
$month = date(m);
$year = date(Y);

$EXdate = "$as[EXyear]"."-"."$as[EXmonth]"."-"."$as[EXday]";
$dnes = "$year"."-"."$month"."-"."$day";

$qd = "select to_days('$EXdate') - to_days('$dnes')";
$rqd = mysql_query($qd) or die(mysql_error());
$ex13 = mysql_fetch_array($rqd);

if($col == "cococo")
{
$col = "dddddd";
}
else
{
$col = "cococo";
}
echo "<tr style=\"font-size:12\">
<td><a class=TN href=\"job-info.php?job_id=$as[job_id]\"><b><font size='1' face='Verdana' color='#000099'> $as[position]</a></b></font></td><td><font size='1' face='Verdana' color='black'> $as[JobCategory] </font></td><td align=center><font size='1' face='Verdana' color='black'> $ex13[0] days</font></td>
</tr>";
}

if($sm == 'or')
{
$qs2 = "select * from job_post ".(($sch)?"where ".join(" or ", $sch):"");
}
elseif($sm == 'and')
{
$qs2 = "select * from job_post ".(($sch)?"where ".join(" and ", $sch):"");
}
$rqs2 = mysql_query($qs2) or die(mysql_error());
$rr2 = mysql_num_rows($rqs2);

echo "</table>";

echo "<table width=95% align=center><tr>";

if ($rr2 <= $ByPage && $Start == '0')
{

}

if ( $Start > 0 )
{
$nom1 = $Start - $ByPage;
echo "<td align=left><br><a href=\"job-search2.php?sm=$sm& position=$position& CompanyCountry=$CompanyCountry& JobIn=$JobIn& JobCategory=$JobCategory&careerlevel=$careerlevel& target_company=$target_company& relocate=$relocate& country=$country& city=$city& kw=$kw& Start=$nom1\"><font font size='2' face='Verdana' color='#000099'>&lt;&nbsp;previous page</font></a><br></td>";
}

if ($rr2 > $Start + $ByPage ¦¦ ($Start == 0 && $rr2 > $ByPage))
{
$nom = $Start + $ByPage;
echo "<td align=right><br><a href=\"job-search2.php?sm=$sm& position=$position& CompanyCountry=$CompanyCountry& JobIn=$JobIn& JobCategory=$JobCategory& careerlevel=$careerlevel& target_company=$target_company& relocate=$relocate& country=$country& city=$city& kw=$kw& Start=$nom\"><font font size='2' face='Verdana' color='#000099'>next page&nbsp;&gt;</font></a><br><br></td>";
}

echo "</tr></table>";

[edited by: jatar_k at 3:16 pm (utc) on Sep. 15, 2005]
[edit reason] fixed sidescroll [/edit]

adammc

10:21 am on Sep 15, 2005 (gmt 0)

10+ Year Member



Can anyone help?

jatar_k

3:20 pm on Sep 15, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



could you boil that code down to the sql statements, large code dumps like that are daunting and take a lot of time for other people to debug/figure out.

general question

when 2 words are passed what do you do with them?

do you split them on the space and use like and like or do you just pass them as a single param to your query?

adammc

12:20 am on Sep 20, 2005 (gmt 0)

10+ Year Member



Sorry, I didnt write this piece of code, thats why I am having so much trouble figuring it out :(

If I understand you correctly this is the code (i think) that searches the database for the keyword that the user sedarches for :

$sch[] = "position like '%$_GET[kw]%' or description like '%$_GET[kw]%'";

jatar_k

2:30 pm on Sep 20, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



well, is it all the search types that don't work or just the one you mentioned?

I would try echo'ing the constructed queries (there are 2) to the browser to see if they are constructed properly for the case in which you search script is dying. Add 2 echo lines and a die since we only want to see the queries.

before these 2 lines in your code
$rqs = mysql_query($qs) or die(mysql_error());
$rqss = mysql_query($qss) or die(mysql_error());

add these
echo '<p>qs: ',$qs;
echo '<p>qss: ',$qss;
die();