Cheap Buy Sell Online shopping |
Online Shopping |
| | Home | Add Link | New Links | Popular Links | Top Rated |Search | Webmaster | Online Shopping |
How to improve your website with Yahoo-like web directoryHow to improve your website with Yahoo-like web directory Copyright © Sergey Popov, xllentSOFT.com - August, 2003 Download sample sources here: webdir.zip Who should use this tutorial?This tutorial is intended for programmers studying PHP and MySQL. It may be useful for webmasters and programmers interested in improvement and development of their web sites as well.PrerequisitesYou will need a basic knowledge of the PHP and JavaScript programming languages, HTML, SQL, and relational database concepts. You will need PHP 4.2.0 or higher and MySQL 3.23.49 or higher installed and running on your computer.What is web directory?Web directory is organized, categorized, hierarchical listing of hyperlinks. It can be categorized by geographical region, topical subject or something else depending upon your website theme. Yahoo! Directory, Open Directory Project and Google Directory are some of the best-known web directories.Why web directory?The list of hierarchically organized items is very useful. It helps the user to find necessary information more quickly. Users feel more confidence working with hierarchical lists. Just remember how often you use them. Therefore, web directory is a good way to improve your website usability. Description of the database structureThe most of web directories have similar simple structure: categories or subcategories list at the top of the page and related links list at the bottom. We need two tables in the database to support such layout: "MyCategories" table and "MyLinks" table. These tables have the following structure: "MyCategories" table: "MyCategories" table creation query: CREATE TABLE MyCategories "MyLinks" table: "MyLinks" table creation query: CREATE TABLE MyLinks You can execute above SQL queries through your favorite MySQL client manually or run the "createMyTables.php" script. The "createMyTables.php" script includes the "dbConfig.inc.php" file, which contains definitions for the following MySQL server connection parameters:
The "createMyTables.php" script uses simple algorithm:
Simple web directory engine scriptsProposed web directory engine consists of the following files:
dbUtils.inc.php auxiliary include fileThis include file contains definition for the "GetCategoriesPath()" function. The "GetCategoriesPath()" function builds HTML code for displaying path from the root of the web directory to the current directory. It uses current category ID as parameter. Category ID, which equal to "0", represents web directory root.The second parameter is a name of the page, which used for the correct link creation. The "GetCategoriesPath()" function uses active MySQL connection. Please keep this in mind if you want to use it for your own purposes. We use the following SQL query to obtain name of the specified category and parent category ID: SELECT iParentCategoryID, sCategoryName This query executed each time with new [Current Category ID] value. The ID of the parent of the current category used as [Current Category ID] for the next iteration. Function finishes execution and returns result when parent category ID is equal to 0. viewWebDirectory.php scriptThis script displays web directory taking current category ID as parameter. It displays top-level categories and links by default.Page layout:
Categories List SELECT iPKMyCategoryID, sCategoryName SELECT sLinkName, sLinkURL, sLinkDescription The "mysql_query()" PHP function sends these queries to the currently active database on the MySQL server. We use "while" PHP loop to transform each row of results of these queries to separate HTML tag. The "mysql_fetch_assoc()" PHP function used to fetch a result row as an associative array. editCategories.php scriptThis page is necessary for entering new categories and links. It takes category ID as parameter. Entered data passed to the processData.php script for processing.Page layout:
Subcategories count SELECT COUNT(*) SELECT COUNT(*) Than we populate subcategories drop-down list. We use the same technique as in the "viewWebDirectory.php" script. The drop-down list is created using <SELECT> HTML element. Selected category ID is submitted to the same "editCategories.php" script using the GET method. So the user can navigate through the web directory categories staying in the editing mode. Two simple HTML forms are placed below on the page: "frmCatAdd" form for entering new category name processData.php scriptThis script receives POST parameters from the "editCategories.php" script, builds INSERT query and passes it to the database server, displays result of the operation. The user has possibility to return to the data entering process.The "switch" PHP statement is used to determine which data was passed. The "mysql_query()" PHP function is used to send INSERT query to the MySQL server. How to use samplesHere are some recommendations on how to use samples: Unpack webdir.zip
into a single folder on your web server. Add attractive web design. Web pages in my sample are very simple, so
you can improve them easily. Last noteI have used PHP and MySQL in this tutorial because they are free and widely available. Described web directory engine creation technique is quite simple and universal. It can be implemented using your favorite server side scripting software and SQL server software. Feel free to send to us your comments or questions: feedback@xllentsoft.com |
|
![]() | Best Shops |