hi

A few thoughts

Firstly wouldn't it be easier to store the resumes in the database?

then 'SELECT * from table where cand_resume_text LIKE "%keyword[1]%" or
cand_resume_text LIKE "%keyword[2]%"

bit inefficient but it works, and opening lots of files is also inefficient.

or


SELECT * from table



while ($row = mysql_fetch_array($result))
{
$found_it=0;

 for keywords....
  {
   if(eregi($kw, $row["resume_text"]))
     {
      $found_it=1;
      $found_one=1;
     }
  }//end for

if($found_it==1) print(.....)

}//end while

if(!$found_one) print "failed"


(I always mark the end of a bracket set, makes debugging easier...)

For your code......

you are printing the result after every keyword check, which will be
serveral times per record, if you have more than one keyword.

Mark success or not by setting a variable and print only when $found_it==1,
resetting $found_it after each loop ;






 while ($row = mysql_fetch_array($result))
 {
$found_it=0;

 $id = $row['id'];

 $FirstName = $row['FirstName'];

 $LastName = $row['LastName'];

 $filename = "/home/sites/madden.williamsen.net/web/recruiter/resumes/"
 .$row['ResumeUp'];

 $fd = fopen($filename,"r");

 $contents = fread($fd, filesize($filename));

 $keywords = explode( $delimiter, $words );

 for ($i=0; $i < count($keywords); $i++) {

 $kw = $keywords[$i];

 if( eregi($kw, $contents) )
 {
   $found_it=1;
//set var to show a success - don't reset
$found_at_least_one=1;
 }//end if

 }//end for

if($found_it==1)
{
 echo "The Words $kw has been found in the resume of
 <a href=\"show_can.php?id=$id\">$LastName, $FirstName</a>
 <br>";
}//end if

 }//end while

if(!$found_at_least_one)  echo "Your Search Returned Zero Records<br>";


hth

Peter


-----------------------------------------------
Excellence in internet and open source software
-----------------------------------------------
Sunmaia
www.sunmaia.net
[EMAIL PROTECTED]
tel. 0121-242-1473
-----------------------------------------------

> -----Original Message-----
> From: Todd Williamsen [mailto:[EMAIL PROTECTED]]
> Sent: 10 February 2002 16:54
> To: [EMAIL PROTECTED]
> Subject: [PHP-DB] If Statement that makes me cry
>
>
> This script is confusing the hell out of me...
>
> What its suppose to do is do a search on documents, and then is it finds
> something say who and where it is, but it repeats the message for
> every hit.
>
> Same goes with the message when there is no results, it repeats
> it for every
> record. All I want it do is say "The results for $kw"
>
> the list here
>
> then when no results are returned, just say the message once..
>
> the results for "$kw" returned zero results.
>
> here is the script
>
> <?
> include "variables.php";
> $delimiter = ",";
>
> $connection = @mysql_connect($databaseserver, $databaseuser,
> $databasepass)
> or die ("could not connect to database");
> $db = @mysql_select_db($databasename, $connection) or die("Could
> not select
> database");
> $sql = "SELECT id, FirstName, LastName, ResumeUp FROM $canidatetable";
> $result = mysql_query($sql, $connection) or die("Couldn't execute query");
>
> while ($row = mysql_fetch_array($result))
> {
> $id = $row['id'];
>
> $FirstName = $row['FirstName'];
>
> $LastName = $row['LastName'];
>
> $filename = "/home/sites/madden.williamsen.net/web/recruiter/resumes/"
> .$row['ResumeUp'];
>
> $fd = fopen($filename,"r");
>
> $contents = fread($fd, filesize($filename));
>
> $keywords = explode( $delimiter, $words );
>
> for ($i=0; $i < count($keywords); $i++) {
>
> $kw = $keywords[$i];
> =============================================
> THE TROUBLE SPOT
> =============================================
> if( eregi($kw, $contents) )
> {
> echo "The Words $kw has been found in the resume of
> <a href=\"show_can.php?id=$id\">$LastName, $FirstName</a>
> <br>";
> }
> else {
>
> echo "Your Search Returned Zero Records<br>";
> }
> }
> }
> ===========================================
> ==========================================
> fclose($fd);
>
> ?>
>
>
>
> --
> PHP Database Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php


-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to