A Taxonomy Browser for Drupal
On a resource site I constructed for a medical facility, the readers need to have an easy “browse by topic” feature on the home page, along with other text. So I created a sort of block that can be dropped in to the middle of a static php page and function as a browser on the home page. The site is now access restricted, but a screenshot is here:
_______begin copying databaseConnectionScript.php text here________
<?php
$hostname_databaseName = “localhost”; // if mysql runs on the same server, leave this set to “localhost” but if it runs from a different server, replace “localhost” with “yourMySqlServer.com”
$database_databaseName = “databaseName”;
$username_databaseName = “user”;
$password_databaseName = “password”;
$connectionString = mysql_pconnect($hostname_databaseName, $username_databaseName, $password_databaseName) or die(mysql_error());
?>
______________end databaseConnectionScript.php text_____________
Next, copy everything between the lines and paste into the “body” text box of a drupal php page. Replace all “yourServer.com” references with the URL of your drupal site.
_____________begin copying browser code here_________________________________________
require_once(‘connections/databaseConnectionScript.php’);
mysql_select_db($database_databaseName, $connectionString);
$query_vocabulary1 = “SELECT * FROM term_data WHERE term_data.vid = 1 ORDER BY name”;
$vocabulary1 = mysql_query($query_vocabulary1, $connectionString) or die(mysql_error());
$row_vocabulary1 = mysql_fetch_assoc($vocabulary1);
$totalRows_vocabulary1 = mysql_num_rows($vocabulary1);
$maxRows_vocabulary2 = 10;
$pageNum_vocabulary2 = 0;
if (isset($HTTP_GET_VARS[‘pageNum_vocabulary2’])) {
$pageNum_vocabulary2 = $HTTP_GET_VARS[‘pageNum_vocabulary2’];
}
$startRow_vocabulary2 = $pageNum_vocabulary2 * $maxRows_vocabulary2;
mysql_select_db($database_databaseName, $connectionString);
$query_vocabulary2 = “SELECT * FROM term_data WHERE term_data.vid = 2 ORDER BY name”;
$query_limit_vocabulary2 = sprintf(“%s LIMIT %d, %d”, $query_vocabulary2, $startRow_vocabulary2, $maxRows_vocabulary2);
$vocabulary2 = mysql_query($query_limit_vocabulary2, connectionString) or die(mysql_error());
$row_vocabulary2 = mysql_fetch_assoc($vocabulary2);
if (isset($HTTP_GET_VARS[‘totalRows_vocabulary2’])) {
$totalRows_vocabulary2 = $HTTP_GET_VARS[‘totalRows_vocabulary2’];
} else {
$all_vocabulary2 = mysql_query($query_vocabulary2);
$totalRows_vocabulary2 = mysql_num_rows($all_vocabulary2);
}
$totalPages_vocabulary2 = ceil($totalRows_vocabulary2/$maxRows_vocabulary2)-1;
mysql_select_db($database_databaseName, $connectionString);
$query_vocabulary3 = “SELECT * FROM term_data WHERE term_data.vid = 3 ORDER BY name”;
$vocabulary3 = mysql_query($query_vocabulary3, $complia_drupalcvs3) or die(mysql_error());
$row_vocabulary3 = mysql_fetch_assoc($vocabulary3);
$totalRows_vocabulary3 = mysql_num_rows($vocabulary3);
mysql_select_db($database_databaseName, $connectionString);
$query_vocabulary4 = “SELECT * FROM term_data WHERE term_data.vid = 4 ORDER BY name”;
$vocabulary4 = mysql_query($query_vocabulary4, $connectionString); or die(mysql_error());
$row_vocabulary4 = mysql_fetch_assoc($vocabulary4);
$totalRows_vocabulary4 = mysql_num_rows($vocabulary4);
?>
<html>
<head>
<meta http-equiv=”Content-Type” content=”text/html; charset=iso-8859-1″>
<style type=”text/css”>
<!–
.smallType {
font-size: 12px;
}
.tabs {
font-family: Verdana, Arial, Helvetica, sans-serif;
font-size: 10px;
font-weight: bold;
text-align: center;
border-right-color:#000000;
border-right-width:1px;
border-right-style:solid;
border-bottom-color:#FFCC00;
border-bottom-width:6px;
border-bottom-style:solid;
border-collapse:collapse;
}
–>
</style>
</head>
<body>
<table><tr><td>
<div align=”right”>
<table width=”300″ border=”0″ cellpadding=”0″ cellspacing=”0″ class=”tabs”>
<tr>
<td bgcolor=”#DDDDDD”><a href=”http://yourServer.com/title_browse6″>BROWSE BY TITLE</a> </td>
<td bgcolor=”#FFCC00″><a href=”http://yourServer.com/browse”>BROWSE BY TOPIC </a></td>
<td bgcolor=”#DDDDDD”><a href=”http://yourServer.com/taxonomy_browser”>ADVANCED SEARCH</a></td>
</tr>
</table> </div>
<table width=”600″ border=”0″ cellspacing=”0″ cellpadding=”6″>
<tr valign=”top”>
<td width=”150″>
<table border=”0″ cellpadding=”1″ cellspacing=”3″ color=”fff”>
<tr>
<td class=”smallType”><b>Subject</b><br> </td>
</tr>
<?php do { ?>
<tr >
<td class=”smallType”><a href=”http://yourServer.com/taxonomy/page/or/<?php echo $row_vocabulary1[‘tid’]; ?>”><?php echo $row_vocabulary1[‘name’]; ?></a></td>
</tr>
<?php } while ($row_vocabulary1 = mysql_fetch_assoc($vocabulary1)); ?>
</table></td>
<td width=”135″>
<table border=”0″ cellpadding=”3″ cellspacing=”3″>
<tr>
<td class=”smallType”><b>Target<br>
Audience</b> </td>
</tr>
<?php do { ?>
<tr>
<td class=”smallType”><a href=”http://yourServer.com/taxonomy/page/or/<?php echo $row_vocabulary2[‘tid’]; ?>”><?php echo $row_vocabulary2[‘name’]; ?></a></td>
</tr>
<?php } while ($row_vocabulary2 = mysql_fetch_assoc($vocabulary2)); ?>
</table></td>
<td width=”157″>
<table border=”0″ cellpadding=”3″ cellspacing=”3″>
<tr>
<td class=”smallType” ><b>Patient <br>
Population</b></td>
</tr>
<?php do { ?>
<tr>
<td class=”smallType”><a href=”http://yourServer.com/taxonomy/page/or/<?php echo $row_vocabulary3[‘tid’]; ?>”><?php echo $row_vocabulary3[‘name’]; ?></a></td>
</tr>
<?php } while ($row_vocabulary3 = mysql_fetch_assoc($vocabulary3)); ?>
</table></td>
<td width=”25″>
<table border=”0″ cellpadding=”3″ cellspacing=”3″>
<tr>
<td class=”smallType”><b>Requirement <br>
Level</b></td>
</tr>
<?php do { ?>
<tr>
<td class=”smallType”><a href=”http://yourServer.com/taxonomy/page/or/<?php echo $row_vocabulary4[‘tid’]; ?>”><?php echo $row_vocabulary4[‘name’]; ?></a></td>
</tr>
<?php } while ($row_vocabulary4 = mysql_fetch_assoc($vocabulary4)); ?>
</table></td>
</tr>
</table></td></tr></table>
<p> </p>
</body>
</html>
<?php
mysql_free_result($vocabulary1);
mysql_free_result($vocabulary2);
mysql_free_result($vocabulary3);
mysql_free_result($vocabulary4);
?>
___________end copying browser code here_________