#native_company# #native_desc#
#native_cta#

Dynamic Link List

By Stephan jau
on February 22, 2001

Version: v1.0

Type: Full Script

Category: Networking

License: GNU General Public License

Description: Hello, this is one of my first scripts.

It lets you create an link list for your webpage based on categories. This one works on with PHP / MySQL. Currently, the categories are sorted by the time of creation… first one created => first one shown.

If you have any improvements, please mail me at [email protected]

Ok, the inc file configures the overall layout.
index.php is the main file
post.php is the form to add new entries
link.php is the form submission and includes the index.php file.
linklist.sql is the file containing the MySQL table parameters.

************************************************************
*Important:                                                *
*You can use this code freely on your website / homepage.  *
*If you have some suggestions for improvement, please mail *
*the specifications to [email protected]                *
*Thanks!!!                                                 *
************************************************************

linklist.sql

/* start linklist.sql

CREATE TABLE linklist (
   name varchar(50) NOT NULL,
   description varchar(120) NOT NULL,
   url varchar(80) NOT NULL,
   banner varchar(80) NOT NULL,
   category varchar(50) NOT NULL
);

/* end linklist.sql



config.inc

/* start config.inc

<?

$PostPage = "post.php"; // The page with the form on it
$gbPage = "index.php";  // The main page

$notify = 1; // Would you like to be notified when a link is added? 1 = yes, 0 = no
$my_email = ""; // Enter your email address
$subject = "Link Entry" ; // Enter the subject of the notification email


$username = ""; // Username for database here
$password = ""; // Password for database here
$db_name =  ""; // Name of your database here

// Link Table Layout
$table_width="100%";
$table_border="0";
$cellspacing="5";
$cellpadding="5";
$table_height="";
$table_bgcolor="";
$bordercolor="";
$td_width="20"; // Indent of the links!!!
$td_height="20";
$td_bgcolor="";

?>

/* end config.inc



index.php

/* start index.php

<html>
<head>
<title></title>
</head>
<body>

<?

include ("config.inc");

//connect
mysql_connect( "localhost", "$username", "$password") or die( "Unable to connect to SQL server");
mysql_select_db( "$db_name") or die( "Unable to select database");

// Get all catetgories
$result = mysql_query("SELECT category from linklist");
$array_category = array();
while ($row = mysql_fetch_array ($result)) {
$array_temp = array($row[0]);
$array_category = array_merge($array_category, $array_temp);
}
mysql_free_result ($result);

// Remove multiple entries
$array_category = array_unique($array_category);

// Sorting on natural algorithm
// if ($sorting="1") { $array_category = natsort($array_category);}

// Set pointer to first entry
reset ($array_category);

while (list ($key, $val) = each ($array_category)) {

?>
<p><font size="+2"><? echo $val; ?></font><br>
</p><table width="<? echo $table_width; ?>" border="<? echo $table_border; ?>"
cellspacing="<? echo $cellspacing; ?>" cellpadding="<? echo $cellpadding; ?>" height="<?
echo $table_height; ?>" bgcolor="<? echo $table_bgcolor; ?>" bordercolor="<? echo $bordercolor; ?>">

<?

$query = "SELECT name, description, url, banner from linklist where category='$val' order by name";
$insert = MYSQL_QUERY($query);
$number = MYSQL_NUMROWS($insert);
$i = 0;

while ($i < $number) {
$name = mysql_result($insert,$i,"name");
$name = stripslashes($name);
$description = mysql_result($insert,$i,"description");
$description = stripslashes($description);
$url = mysql_result($insert,$i,"url");
$url = stripslashes($url);
$banner = mysql_result($insert,$i,"banner");
$link_url = ("<a href=$url>$name</a>");
$link_banner = ("<a href=$url><img src=$banner></a>");

if ($banner=="") { ?>
  <tr>
    <td width="<? echo $td_width; ?>" height="<? echo $td_height; ?>" background="<? $td_bgcolor; ?>"> </td>
    <td width="100%" height="<? echo $td_height; ?>" background="<? $td_bgcolor; ?>"><font size="+1">
<? echo $link_url; ?></font><? if ($description!="") { ?>   ( <? echo $description; ?> ) <? } ?></td>
  </tr>
<? } else { ?>
  <tr>
    <td width="<? echo $td_width; ?>" height="<? echo $td_height; ?>" background="<? $td_bgcolor; ?>"> </td>
    <td width="100%" height="<? echo $td_height; ?>" background="<? $td_bgcolor; ?>"><? echo $link_banner; ?></td>
  </tr>
<? if ($description!="") { ?>
  <tr>
    <td width="<? echo $td_width; ?>" height="<? echo $td_height; ?>" background="<? $td_bgcolor; ?>"> </td>
    <td width="100%" height="<? echo $td_height; ?>" background="<? $td_bgcolor; ?>">(<? echo $description; ?>)</td>
  </tr>

<? } } $i++; } ?>

</table>
<p><br>
  <br>
  <? } ?>
</p>
<p> </p>
<p><b><font size="+1"Add Link</font></b><font size="+1">: </font></p>
<ul>
  <p>If you want to submit a new link then open <a href="post.php">this formular</a></p>
</ul>
<p>  </p>
</body>
</html>

/* end index.php



post.php

/* start post.php

<html>
<head>
<title></title>
</head>
<BODY>

<? include ("config.inc");  ?>
<P>Please fill in the following form or go back <a href="index.php">to the linklist</a></P>
<P> </P>

<form name="link" method="post" action="link.php">

  <table width="100%">
    <tr>
      <td width="19%">
        <p>Link Name:</p>
        <p> </p>
      </td>

      <td width="81%">
        <p>
          <input type="text" name="name" maxlength="50" size="50">
        </p>
        <p>  </p>
      </td>
          </tr>

    <tr>
      <td width="19%">
        <p>URL:</p>
        <p> </p>
      </td>

      <td width="81%">
        <p>
          <input type="text" name="url" maxlength="80" size="50">
          <br>
          Please use following URL syntax: http://www.mypage.com</p>
        <p>  </p>
      </td>
          </tr>

    <tr>
      <td width="19%">
        <p>URL of banner (if available):</p>
        <p> </p>
      </td>

      <td width="81%">
        <p>
          <input type="text" name="banner" maxlength="80" size="50">
        </p>
        <p>  </p>
      </td>
          </tr>

    <tr>
      <td width="19%">
        <p>Category:</p>
        <p> </p>
      </td>

      <td width="81%">
        <p>
          <select name="category_1" size="1">
            <? //connect
mysql_connect( "localhost", "$username", "$password") or die( "Unable to connect to SQL server");
mysql_select_db( "$db_name") or die( "Unable to select database");

// Get all catetgories
$result = mysql_query("SELECT category from linklist order by category");
$array_category = array();
while ($row = mysql_fetch_array ($result)) {
$array_temp = array($row[0]);
$array_category = array_merge($array_category, $array_temp);
}
mysql_free_result ($result);

// Remove multiple entries
$array_category = array_unique($array_category);

// Set pointer to first entry
reset ($array_category);

while (list ($key, $val) = each ($array_category)) {
if(($val!="Unsere Patenverbindung in Bern:") AND ($val!="Unsere Patenkinder in Gossau:")) { ?>
            <option>
            <? echo $val; ?>
            </option>
            <? } } ?>
          </select>
          <br>
          If your site doesn't fit to any of the existing categories,<br>
          please enter the name of a new on in the field below:<br>
          <input type="text" name="category_2" maxlength="50" size="50">
        </p>
        <p> </p>
        </td>
          </tr>

    <tr>
      <td width="19%">
        <p>Short description (if applicable):</p>
        <p> </p>
      </td>

      <td width="81%">
        <p>
          <input type="text" name="description" maxlength="120" size="50">
        </p>
        <p>  </p>
      </td>
          </tr>
        </table>

  <p>
    <input type=submit name=submit value="Hinzuf gen">
        Please press the Submit button only once. The submission can take a little while.
  </p>
  </form>

</BODY>
</HTML>

/* end post.php



link.php

/* start link.php

<HTML>
<HEAD></HEAD>
<BODY>
<?

include ("config.inc");

if (($name == "") AND ($url == "")):

$error1 = "<font face='Arial' color='Red'><STRONG>Please fill in the fields Name and URL:</STRONG></font><br><br>";

echo $error1;

include($PostPage);

else:

if ($category_2==""):

$category = $category_1;

else:

$category = $category_2;

endif;

//connect

$mysql_link = mysql_pconnect( "localhost", "$username", "$password") or die 
("Cannot reach the server. Please send a mail to $my_email.");
mysql_select_db( "$db_name") or die( "Cannot reach the database. Please send a mail to $my_email.");

$insert = "INSERT INTO linklist(name, description, url, banner, category) VALUES('$name', '$description', '$url', '$banner', '$category')";
$mysql_insert = mysql_query($insert, $mysql_link) or die 
("Please send a mail to $my_email and add the information that there could be made no new entries.");

// EMAIL THE NEW POST

if ($notify == 1):

mail
(
"$my_email",
"Link Eintrag",
"Name : $name
URL: $url
Banner: $banner
Beschreibung: $description
Category: $category"
);
endif;

include($gbPage);

endif;

?>

</BODY>
</HTML>

/* end link.php