Re: If Statement that makes me cry

From: Date: Mon, 11 Feb 2002 16:41:18 +0000
Subject: Re: If Statement that makes me cry
References: 1 2  Groups: php.db 
Request: Send a blank email to php-db+get-16807@lists.php.net to get a copy of this message
Peter, Neither storing the documents in the database and storing them as a file is a good choice. My bottomline is to be able to store them on a fileserver for backup purposes later on. This is only a temporary solution. My ultimate goal is to be able to search within a MS Word Document, but it seems that is a moot point unless I take the whole application and migrate it to ASP and COM+ which I know nothing about. Plus, the client's requirements are vague to say the least. They have the atitude, "Build something along these lines and we will see what you come up with and we will go from there." That isn't what I had in mind. But I know the ability to search within a Word document is a key factor. That is a drawback of Open Source, you cannot access the Microsoft World which 80% of the computer users use as Office Applications and is considered a standard. I know, the Open Source community doesn't like that reality, but its true. When somebody submits a resume to apply for a job, what format does a recuiter or employer look for? MS Word. "Peter Lovatt" <pjln1@sunmaia.net> wrote in message news:NFBBKAGAILLHPFOOAKFIOEBLCOAA.pjln1@sunmaia.net... > 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 > info@sunmaia.net > tel. 0121-242-1473 > ----------------------------------------------- > > > -----Original Message----- > > From: Todd Williamsen [mailto:todd@williamsen.net] > > Sent: 10 February 2002 16:54 > > To: php-db@lists.php.net > > 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 >

« previous php.db (#16807) next »