WeberDev.com PHP and MySQL Code

LOG IN
BEGINNER GUIDES  |  PHP CLASSES  |  CODE SEARCH  |  ARTICLES SEARCH  |  PHP FORUMS  |  PHP MANUAL  |  PHP FUNCTIONS LIST  |  WEB SITE TEMPLATES
Start typing to search for PHP and MySQL Code Snippets and Articles Search
Submit a code Example / Snippet Submit Your Code
Search Engine Optimization Monitor SEO Monitor
Web Site UpTime Monitor UpTime Monitor
WeberDev's Monthly code contest PHP Code Contest
Your Personal Examples List My Favorite Examples
Your Personal Articles List My Favorite Articles
Edit Account Info Update Your Profile
PHP Code Search
Web Development Forums
Learn MySQL Playing Trivia
PHPBB2 Templates
Web Development Index
PHP Web Logs (BLogs)
Web Development Resources
Web Development Content
PHPClasses
PHP Editor
PHP Jobs
Vision.To Design
Ajax Tutorials
PHP Programming Help
PHP/MySQL Programming
Webmaster Resources
Webmaster Forum
XML meta language
website builder
Submit Site
Forex Trading Online forex trading platform

Go Back Add a Comment Send this example to a friend Add this Article to your personal favoritest for easy future access to your favorite Code Examples and Articles. Submit a code example Print this code example.
BACK ADD A COMMENT SEND TO A FRIEND ADD TO MY FAVORITES ADD CODE EXAMPLES PRINT
Title : Guestbook sort by descending date and can view page by page
Categories : PHP, MS SQL Server, Databases Update Picture
kong khai yun
Date : Jul 05th 1999
Grade : 3 of 5 (graded 5 times)
Viewed : 17787
File : guestbook.php3
Images : No Images for this code example.
Search : More code by kong khai yun
Action : Grade This Code Example
Tools : My Examples List

  Submit your own code examples 
 

<?
//
// Give me comment if I there is a bug on it.
//
//
//
//CREATE DATABASE guest;
//USE guest;
//CREATE TABLE guestbook (
// id mediumint(8) DEFAULT '0' NOT NULL auto_increment,
// name varchar(30) DEFAULT '' NOT NULL,
// email varchar(30) DEFAULT '' NOT NULL,
// comments text DEFAULT '' NOT NULL,
// mdate TIMESTAMP,
// PRIMARY KEY (id)
//);
echo "<HTML><HEAD><TITLE>Guestbook</TITLE></HEAD><BODY>";
mysql_connect( "localhost", "USERNAME", "PASSWORD");
mysql_select_db("guestbook") or die("Error opening database");
$$EXTEND ="";
$ROW_PER_PAGE = 10;
$rel = mysql_query("select * from guestbook order by mdate DESC");
$MAX_ROW = mysql_num_rows($rel);
if (isset($BUTTON)) {
        $EXTEND = "limit $LOWER_ROW, $UPPER_ROW";
} else {
        $BUTTON = Begin;
        $TMP_NUM = 0 ;
}

        switch ($BUTTON) {
        case Begin:
                $TMP_NUM = 0 ;
                $EXTEND = "limit $ROW_PER_PAGE ";
                break;
        
        case End:
                $TMP_NUM = $MAX_ROW - $MAX_ROW % $ROW_PER_PAGE;
                $LOWER_ROW = $TMP_NUM ;
                if ($LOWER_ROW == $MAX_ROW && $LOWER_ROW != 0) {
                        $LOWER_ROW = $MAX_ROW - $ROW_PER_PAGE;
                        $TMP_NUM = $TMP_NUM - $ROW_PER_PAGE;
                }
                $EXTEND = "limit $LOWER_ROW, $ROW_PER_PAGE";
                break;
        case Prev:
                $TMP_NUM = $CURVALUE - $ROW_PER_PAGE;
                if ($TMP_NUM < 0) {
                $TMP_NUM = 0;
                $LOWER_ROW = 0;
                } else {
                $LOWER_ROW = $TMP_NUM;
                }
                $EXTEND = "limit $LOWER_ROW, $ROW_PER_PAGE";

                break;
        case Next:
                if (($CURVALUE + $ROW_PER_PAGE) < $MAX_ROW ) {
                        $LOWER_ROW = $CURVALUE + $ROW_PER_PAGE;
                        
                }else{
                        $LOWER_ROW = $CURVALUE;
                }
                $TMP_NUM = $LOWER_ROW;
                $EXTEND = "limit $LOWER_ROW, $ROW_PER_PAGE";
                break;
}

if ($argv[0] == "add"):
?>
        <P><FORM NAME="guestbook" ACTION="<?echo $PHP_SELF?>" METHOD=POST><BR>
         <TABLE WIDTH=340 BGCOLOR="#66CCFF" VALIGN="CENTER" BORDER="0" CELLSPACING="1"
CELLPADDING="1">
                 <INPUT TYPE=hidden NAME=cmd VALUE=send>
                        <TR><TD ALIGN="RIGHT">Your Name:</TD>
                                <TD><INPUT TYPE=text NAME=name></TD></TR>
                         <TR><TD ALIGN="RIGHT">Your E-mail: </TD>
                                <TD><INPUT TYPE=text NAME=email></TD></TR>
                        <TR><TD COLSPAN="3">Comments:</TD></TR>
                        <TR><TD COLSPAN="100%" ALIGN="CENTER"><TEXTAREA NAME=comments
COLS=34 ROWS=6></TEXTAREA><BR>
        <CENTER><INPUT TYPE=submit VALUE=Submit><INPUT TYPE=reset
VALUE=Clear></CENTER></TD></TR>         </TABLE> </FORM>

<? include("./tpl/footer.txt");
// if the query string is view, the fetch the guestbook entries
else:
        if (isset($cmd) && $cmd == "send" && $name != '' && $comments != '' ) {
        $comments = nl2br(htmlspecialchars(addslashes($comments)));
        $abc = mysql_query("select * from guestbook where name = '$name' and comments
= '$comments'");
                if (mysql_num_rows($abc)== 0)        {
                        mysql_query("insert into guestbook (name, email, comments) values
('$name', '$email', '$comments')");
                }
        }
        include("./tpl/header.txt");
        echo "<H2>Guestbook Entries</H2>";
        echo "<H4><A HREF=\"$PHP_SELF?add\">My Comments</A></H4>";
        $result = mysql_query("select * from guestbook");
        $row = mysql_num_rows($result);
        echo "<P>There are <I>$row[0]</I> entries in the guestbook.<P>";
        $result = mysql_query( "select UNIX_TIMESTAMP(mdate), name, email, comments from
guestbook order by mdate DESC $EXTEND");

        while ($row = mysql_fetch_row($result)) {
        echo "<TABLE WIDTH=340 BGCOLOR=\"#99CCFF\" VALIGN=\"LEFT\" BORDER=\"0\"
CELLSPACING=\"0\" CELLPADDING=\"5\">";
        echo "<TR>";
        echo "<TD COLSPAN=\"50%\" ><I><FONT SIZE=\"-2\"><B>".date("d-M-Y H:i:s",$row
[0])."</FONT></I></B></TD>";
        echo "<TD COLSPAN=\"50%\" ALIGN=\"RIGHT\"><FONT SIZE=\"-1\"><A HREF=\"mailto:$row
[2]\">$row[1]</A>";
        echo "</TD>";
        echo "</TR>";
        echo "<TR BORDER=\"1\">";
        echo "<TD COLSPAN=\"100%\"BGCOLOR=\"#FFFFCC\">".stripslashes($row[3]);
        echo "</TD>";
        echo "</TR>";
        echo "</TABLE>";
        echo "<BR>";
        }
        ?>
        <FORM NAME="test" ACTION="<?echo $PHP_SELF?>" METHOD=POST>
        <INPUT TYPE=hidden NAME=CURVALUE VALUE=<? echo $TMP_NUM;?>>
        <INPUT TYPE=submit NAME="BUTTON" VALUE=Begin>
        <INPUT TYPE=submit NAME="BUTTON" VALUE=Prev>
        <INPUT TYPE=submit NAME="BUTTON" VALUE=Next>
        <INPUT TYPE=submit NAME="BUTTON" VALUE=End>
        </FORM> <?

endif; ?>



Logs hits to any page which includes it. Automatically utilises page access information left behind by PHP/FI2.0.
Categories : Databases, PHP, mSQL, Databases
Recordset Class for MSSQL database
Categories : PHP Classes, Databases, PHP, MS SQL Server
How to connect to MS SQL 6.x+ database server via ODBC functions of PHP3 compiled with iODBC and Openlink drivers under Linux.
Categories : Databases, MS SQL Server, PHP, ODBC
Scripts to build APACHE - PHP and SQL 7.0
Categories : PHP, Databases, MS SQL Server
This program allows you to upload an ODBC ressource - i.e. an MS-Access database to a MySQL server.
Categories : Databases, MySQL, Complete Programs, PHP, Databases
Convert SQL from oracle,mysql,mssql,sqlite and odbc to SQL compatible
Categories : PHP, PHP Classes, Databases, MySQL, MS SQL Server
Simple class for accessing databases like MSSql Server, Oracle etc by Raju
Categories : PHP, MS SQL Server, Databases, PHP Classes, Oracle
[PHP5] aDB PDO LIKE Database Abstraction. Switch easily from one db server to another, strong errors management, manage transactions, queries preparation and more.
Categories : PHP, PHP Classes, Databases, MS SQL Server, MySQL
Mssql database Manager
Categories : PHP, Databases, MS SQL Server, Classes and Objects, PHP Classes
Unable to select text bigger than 4K from MSsql
Categories : PHP, WinNT, Databases, MS SQL Server
Displaying records of database in more than one page (paging)
Categories : Databases, MySQL, PHP
Accepts a database & hostname from a user and then HTTP username and password. Uses this to connect to a MySQL database. Produces a form based on the tables it finds there to allow the user to do SELECTs, INSERTs, and DELETEs.
Categories : Databases, PHP, MySQL, Complete Programs
Cut your MySQL Connections to 1 line of code
Categories : PHP, Beginner Guides, Databases, MySQL
PhpIBadmin - Web interface to Interbase RBDMS , this is a port of phpMyadmin
Categories : Databases, InterBase, PHP
phpAds, a complete banner and ad management system with detailled tracking and stats.
Categories : MySQL, Complete Programs, Ecommerce, PHP, Databases