httpd-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From David Blomstrom <david_blomst...@yahoo.com>
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 http://www.geozoo.org/stacks/Felidae,
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
(species).

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

If you click the genus Panthera -
http://www.geozoo.org/stacks/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 -
www.geozoo.org/stacks/Panthera leo. This was easy,
because each row in my database table features a
taxon's "Name" (e.g. leo) and "Parent" (e.g.
Panthera).

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.

* * * * *

<?php
$result = mysql_query('select count(*) from
gzanimals');
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">
<?php
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;
  break;
  default:
  $Name = $row['Name'];
  break;
}

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


		
____________________________________________________
Start your day with Yahoo! - make it your home page 
http://www.yahoo.com/r/hs 
 

---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


Mime
View raw message