[PHP-DB] Re: Ordering titles in MySQL (long)

2001-11-01 Thread Cameron Metcalf

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 = 

[PHP-DB] Re: MySQL: alphabetizing, skipping the , a

2001-06-25 Thread Cameron Metcalf

Hey all,
I'm trying to generate a alphabetized list of items
from my database, but I want to alphabetize the list,
skipping the leading articles in the title for each item.

some solutions suggest creating a 2nd (dummy name) column
to alphabetize by, but I don't want to maintain two columns for
my name field. but I've been using the following to ignore 'the ' and 'a
':

$select = mysql_select_db(bases);
$query = SELECT IF(left(nameE,2)='A ' or left(nameE,4)='The ', 
if(left(nameE,2)='A ',right(nameE,length(nameE)-2),
right(nameE, length(nameE)-4)),nameE) as 
alphabet,nameE FROM principle order by alphabet;
$result = mysql_query($query)

but if I want to ignore third or fourth variable, on top of 'the ' and 
'a ', what syntax would I use, to include these additional cases in my
script 
above?

the above query was built on a coding solution I found at
http://www.bitmechanic.com/mail-archives/mysql/May1998/0713.html
*mysql: select statements that ignore the *

Cameron

-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




[PHP-DB] Suppressing NULL values in search results

2001-02-19 Thread Cameron Metcalf

Hey,
I've been using PHP for 'bout a month
and my programming abilities are pretty limited.

I'm using a script (further below) to retrieve
results from a MySQL database. It's intended to retrieve
potentially 6 fields of information.

Some of these fields in the record, though, may be NULL, but then I get
the word "NULL" on my web page

If a field is NULL, how do I change this script, so that only 
those non-NULL fields are displayed?

I've been reading up on arrays, but I can't figure out if my answer
lies there, or in some section 'bout variable re-assignment.  My hunch
is I've got to create a print buffer of some sort, but I can't figure
out
how to do that either.

In my database, p.nameE, u.urlE *are* required whereas 
p.daterange, a.accessE, p.descriptionE, p.subjectE, are not required and
may have
NULL values in my database.

Direct solutions would be appreciated or even if you could suggest a
name/terminology for
this problem, because I've been unable to turn anything up in the
archives/printed literature.

Thanks for your time.

Cameron





html
head
titleSearch Results/title
link REL="stylesheet" HREF="styles/bibnetstyle.css"
/head
body
?php 
include ("styles/bibnethd-e.html")
?
table width="90%" border="0"
trtd width="20%" valign="top"?php 
include ("styles/bibnetnav-e.html")
?/tdtd width="80%" valign="top"
table width="100%" border="0"
?php

$select = mysql_select_db ("bases"); 

$query = "select p.nameE, p.daterange, a.accessE, p.descriptionE,
p.subjectE, u.urlE from principle p, accesstype a, accessdetails ad, url
u, urldetails ud where p.baseID='$baseID' and p.baseID = ad.baseID and
ad.accessID = a.accessID and p.baseID = ud.baseID and ud.urlID =
u.urlID";

$result = mysql_query ("$query"); 

while ($base = mysql_fetch_array ($result))

{
print ("trtd bgcolor=\"#9C\"font size=\"5\"
color=\"#FF\"$base[0]/font/td/trtrtdfont
color=\"#00\"bDate Range:/bnbsp;$base[1]/fontbrfont
color=\"#00\"bAccess Type:/b/fontnbsp;font
color=\"#ff\"b$base[2]/b/fontpfont color=\"#00\"a
href=\"$base[5]\"Connect to $base[0]/a/fontp
a href=\"instructions-e.php?access=$base[2]\"Instructions to connect
to this database from off campus./apfont
color=\"#00\"bDescription of
$base[0]:/bnbsp;$base[3]/fontfont color=\"#00\"pbSubjects
covered in $base[0]:/bnbsp;$base[4]/font/td/tr\n"); 
}
?
/table/td/tr
trtd colspan="2" valign="top"
?php 
include ("styles/bibnetft-e.html")
?/td/tr
trtd colspan="2" valign="top"?php 
include ("dinclude.php")
?/td/tr/table
/BODY
/HTML

-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]