Hi Ian,
I tried a couple different things, trying to chop off leading articles.
I didn't want to maintain a 2nd column for titles, but eventually had to
succumb to this.
(My difficulty is that I'm using French and English titles (for a
bilingual interface), so I actually have four fields:
my fields are labelled as follows:
nameE (english title), nameF (french title), namesortE (english title
with leading article removed), namesortF
(with french leading article removed.
When I enter a title into my database, using a php form,
the leading article is lopped off the front off the title and
this new form of the title is thrown into the record's namesortE
column.
(the same thing happens for the french fields).
Leading articles that I want to remove are stored in
a text file called 'noisewords.txt'
my script looks for words in the text file, and if it
finds a match between the text file entries and the
title I've just entered, it removes the appearance of the word, in
the title.
the 'varnameE' and 'varnameF' fields may throw you off.
it is used as working title. our records go by more than one
title so in order to view the records by title or by variant title
(alphabetically skipping leading articles) I've had to have a separate
table
for titles just for the sake of holding variant names.
please overlook my coding practices in the snippet below. I've had no
formal
training in programming, since my trs-80 days learning BASIC on 2K radio
shack computers.
be assured though, the following does work for me.
I came up with this solution thanks to
olinux
who forwarded me the URL for this article:
http://phpbuilder.com/columns/clay19990421.php3 which even includes a
list of noisewords for you.
Cameron (code below)
***
following is the code I currently use:
stage==1 is the process of data being entered
into the database. stage==2 is the input form that
supplies the data for stage==1.
?php
if($stage == 1)
{
// PROCESS ADD NEW DATABASE RECORD FORM
$connect = mysql_connect(localhost, $username, $password);
$select = mysql_select_db(bases);
// INSERT NEW DATA INTO PRINCIPLE TABLE
while(list($key, $vala) = each ($accessID))
while(list($key, $valf) = each ($formatID))
while(list($key, $valu) = each ($urlID))
while(list($key, $valv) = each ($vendorID))
{
$query = INSERT INTO principle (nameE, nameF,
daterange, descriptionE, subjectE, notesE, descriptionF,
subjectF, notesF, license, accessID, formatID, urlID, vendorID, orbispo,
livedate) VALUES ('$nameE', '$nameF', '$daterange',
'$descriptionE', '$subjectE', '$notesE', '$descriptionF', '$subjectF',
'$notesF', '$license',
'$vala', '$valf', '$valu', '$valv', '$orbispo', '$livedate');
$result = mysql_query($query)
OR die($query . mysql_error());
}
?
?php
// INSERT NEW DATA INTO SOFTWAREDETAILS TABLE
while(list($key, $vals) = each ($softwareID))
{
$query_2 = INSERT INTO softwaredetails (baseID, softwareID) VALUES
('$newbaseID', '$vals');
$result_2 = mysql_query($query_2)
OR die($query . mysql_error());
}
?
?php
// INSERT NEW DATA INTO VARNAME TABLE
{
$query_3 = INSERT INTO varname (varnameE, varnameF, baseID) VALUES
('$nameE', '$nameF', '$newbaseID');
$result_3 = mysql_query($query_3)
OR die($query . mysql_error());
}
?
?php
//TRIMSCRIPT FOR ENGLISH NAMESORT COLUMN IN TABLE PRINCIPLE
$query = select nameE, baseID from principle;
$result = mysql_query($query);
$number = mysql_numrows($result);
$j = 0;
WHILE ($j $number) {
$title = mysql_result($result,$j,nameE);
$qid = mysql_result($result,$j,baseID);
$noise_words = file (noisewords.txt);
$filtered = $title;
$filtered = ereg_replace(^, ,$filtered);
for ($i=0; $i count($noise_words); $i++) {
$filterword = trim($noise_words[$i]);
$filtered = eregi_replace( $filterword , ,$filtered);
}
$filtered = trim($filtered);
$filtered = addslashes($filtered);
$querywords = ereg_replace(,,,$filtered);
$entersorts = UPDATE principle set namesortE = \$querywords\ WHERE
baseID = $qid;
$result_0 = mysql_query($entersorts)
OR die($entersorts . mysql_error());
$j++;
}
//E-STAT special case update ENGLISH
$estate = UPDATE principle set namesortE = \E-STAT\ WHERE baseID =
73;
$result_0 = mysql_query($estate)
OR die($estate . mysql_error());
?
?php
//TRIMSCRIPT FOR FRENCH NAMESORT COLUMN IN TABLE PRINCIPLE
$query = select nameF, baseID from principle;
$result = mysql_query($query);
$number = mysql_numrows($result);
$j = 0;
WHILE ($j $number) {
$title = mysql_result($result,$j,nameF);
$qid = mysql_result($result,$j,baseID);
$noise_words = file (noisewords.txt);
$filtered = $title;
$filtered = ereg_replace(^, ,$filtered);
for ($i=0; $i count($noise_words); $i++) {
$filterword = trim($noise_words[$i]);
$filtered = eregi_replace( $filterword , ,$filtered);
}
$filtered = trim($filtered);
$filtered = addslashes($filtered);
$querywords = ereg_replace(,,,$filtered);
$entersorts = UPDATE principle set namesortF = \$querywords\ WHERE
baseID = $qid;
$result_0 =