httpd-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From David Blomstrom <>
Subject [users@httpd] Mod_rewrite vs 2 Database Table Cells
Date Tue, 23 Aug 2005 17:33:41 GMT
I think this question involves PHP and Apache
mod_rewrite both. But maybe someone can at least give
me an overview here.

If you visit,
you'll see a list of genera that belong to the family
Felidae in the column on the right. Clicking any genus
similarly fetches a list of that genus' children

However, species are properly displayed as TWO names -
Genus + species (or Parent + child). It's also
important practically, because clicking summons a page discussing a
marsupial called Antechinus leo, rather than the more
popular Panthera leo (the lion).

If you click the genus Panthera - - you'll see
that I've taken the first step towards fixing the
problem. My list of species now displays as two names,
and the links similarly point to two names - leo. This was easy,
because each row in my database table features a
taxon's "Name" (e.g. leo) and "Parent" (e.g.

The obvious problem is that no page can be displayed
with a space between Panthera and leo.

How can I fix this? It seems to me there are two
problems here:

1. Physically replace spaces between words with
characters, like underscores ( _ ).

2. Somehow tell the database that when a visitor
clicks Panthera_leo, it's the same as choosing the row
where Name = Leo and Parent = Panthera (NOT the row
where leo is matched with Antechinus, a marsupial).

So which should I do first? If I was display two words
drawn from a single database table cell, I think my
mod_rewrite rule would look like this:

RewriteRule ^stacks/([a-zA-Z_]+)/?$
stacks/index.php?taxon=$1 [L]

Would I use the same rule if I fetched two words from
different cells - e.g. Panthera | leo? What about
THREE words from two cells, like East African | finch?
I can simply experiment, but it's hard to tell whether
my experiment is working because it won't really work
unless my PHP script and mod_rewrite are working
together - right?

I posted my script below. Thanks.

* * * * *

$result = mysql_query('select count(*) from
if (($result) && (mysql_result ($result , 0) > 0)) {
} else {
die('Invalid query: ' . mysql_error());
$taxon = mysql_query ("SELECT Name, NameCommon, Parent
FROM gzanimals AS GZA
WHERE Parent = '$_GET[taxon]'");

echo '<div class="' . $_GET['taxon'] . '">';

<div class="divindex">
echo '<table>';
while ($row = mysql_fetch_array($taxon, MYSQL_ASSOC))
$Name = $row['Name'];
$Parent = $row['Parent'];
$SpName = $Name.$row['Parent'];
switch ( $GZAnimals['Tax'] )
  case 'gen':
  case 'spp':
  $Name = $Parent.' '.$Name;
  $Name = $row['Name'];

echo <<<EOD
     <td class="{$row["Name"]}"><a
echo '</table></div><!--EndDivIndex-->';

Start your day with Yahoo! - make it your home page 

The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:> for more info.
To unsubscribe, e-mail:
   "   from the digest:
For additional commands, e-mail:

View raw message