Alphabetical Title Browser for Drupal
November 12, 2003
Drupal | PHP

Note: See also PHP Alternating Color Table Rows for Drupal or Dreamweaver sites

I needed an alphabetical browser of all published nodes, and couldn't figure out how to do it using existing Drupal tools, so created one in Dreamweaver and made a static page out of it. Maybe someone can make a Drupal module out of? it. It needs at least four big improvements that I can think of -

1. The Dreamweaver connection code needs to be Drupal-ized
2. It is written in the backwards Dreamweaver way - the php gets inserted into the html, rather than having the php output the html as part of the stream of code.
3. It needs to have the alternating table rows
4. It needs to be paged, when the list gets too long.

Ads by Google

Posted by ellen at November 12, 2003 10:46 AM

There are two files here - one is a connection file, probably best to store that outside the web root. the other is the code that gets inserted into your web page.

# FileName=\"Connection_php_mysql.htm\"
# Type=\"MYSQL\"
# HTTP=\"true\"
$hostname_yourDatabase = \"localhost\";
$database_yourDatabase = \"yourDatabase3\";
$username_yourDatabase = \"username\";
$password_yourDatabase = \"password\";
$yourDatabase = mysql_pconnect($hostname_yourDatabase, $username_yourDatabase, $password_yourDatabase) or die(mysql_error());
Code that gets inserted into static page:

mysql_select_db($database_yourDatabase, $yourDatabase);
$query_alphabeticalNodes = \"SELECT nid, type, title FROM node WHERE type = \'story\' ORDER BY title ASC\";

$alphabeticalNodes = mysql_query($query_alphabeticalNodes, $yourDatabase) or die(mysql_error());
$row_alphabeticalNodes = mysql_fetch_assoc($alphabeticalNodes);
$totalRows_alphabeticalNodes = mysql_num_rows($alphabeticalNodes);



<TITLE>Untitled Document</TITLE>
<META http-equiv=\"Content-Type\" content=\"text/html; charset=iso-8859-1\">

<TABLE border=\"0\" cellpadding=\"0\" cellspacing=\"6\">
<TR valign=\"top\" class=\"dark\">
<?php do { ?>
<TR valign=\"top\" class=\"dark\">
<TD><P> <?php echo ++$orderNum; ?></P>
<TD><A href=\"<?php echo $row_alphabeticalNodes[\'nid\']; ?>\"><?php echo $row_alphabeticalNodes[\'title\']; ?></A></TD>
<?php } while ($row_alphabeticalNodes = mysql_fetch_assoc($alphabeticalNodes)); ?>
<P> </P>
<P> </P>

Ads by Google

Ads by Google

 RSS   |   Contact Me

Ads by Google