Creating the guestbook has two parts, the table to hold the guestbook records and the script to insert and select records from the database
table.
The structure of the table should look similar to this:
CREATE TABLE guests (
id int(10) unsigned NOT NULL auto_increment,
guest varchar(50) NOT NULL default '',
message varchar(200) NOT NULL default '',
date datetime default NULL,
PRIMARY KEY (id)
) ;
The guestbook script has three sections - the code for the form, the code for saving the form data, and the code for displaying the data.
A Closer Look: Five MySQL functions that handle query results
Assigning variable names to a MySQL result set
After executing a query to select data from a MySQL table there are several functions you can use to perform operations on the retrieved data.
mysql_result() - fetches the contents of the specified cell
mysql_data_seek() - moves to the specified row of a result set
mysql_fetch_array() - fetches the next row in the result set as an array
mysql_fetch_object() - fetches the next row in the result set as an object
PHP shoutbox
Creating a shoutbox using PHP
I have seen a shoutbox described as a chat application to a guestbook. I do not consider a shoutbox a chat application, I think it's more of a simple comment system. Visitors to your website can quickly leave feedback without having to register for chat or a forum and they do not have to answer all the questions that would normally be in a guestbook. Creating a shoutbox with PHP and MySQL is not very difficult.
First create a table to hold the shoutbox data:
CREATE TABLE myshout (
shoutid int(4) NOT NULL auto_increment,
Design an Online Chat Room with PHP and MySQL by Rory Canyon
In this article, you will learn how to design and develop a simple online chat room with PHP and MySQL. This tutorial explains every steps of the development, including both database design and PHP programming. Basic computer skills and knowledge of HTML and PHP are required. Ok, let's begin now.
Step 1: Design Database Table.
Create table "chat" in MySQL database to store basic chat information: chtime (chat time), nick (user nickname) and words (chat message, less than 150 characters)
mysql> CREATE TABLE chat
Generating dynamic XML
Transform an XML document dynamically created by PHP to HTML
PHP can create XML documents on-the-fly (dynamically) and then use its XSLT extension to transform to HTML. This means that data retrieved from a database (in this case MySQL) can be formatted as XML and via an XSL style sheet, to be presented as HTML.
Count the number of MySQL Queries
How to count the number of MySQL queries used by your script
One way of optimizing your scripts that connect to MySQL databases is to determine how many queries to the database your script makes. If you would like to count the number of queries, you can write a script that will do so. You use this function in place of the regular mysql_query() function.
PHP Code:
<?php function cnt_mysql_query($sql=FALSE) { static $queries = 0; if (!$sql) return $queries; $queries ++; return mysql_query($sql); } $sql= "SELECT 8+9";
Creating a random link generator
The random generator code that this generator uses was originally posted to the PHP mailing list. View the original: Retrieve random Sql results
SQL for links table:
# Table structure for database table 'links'
#
CREATE TABLE links (
id tinyint(5) DEFAULT '0' NOT NULL auto_increment,
name char(250) NOT NULL,
url char(250) NOT NULL,
alt char(250) NOT NULL,
PRIMARY KEY (id)
);
PHP Code:
<?php $db = mysql_connect("server", "username", "password"); mysql_select_db("database",$db) or die ("Unable to connect to database");
Introduction
PHP (recursive acronym for "PHP: Hypertext Preprocessor") is a server-side scripting language that can be used on a host of webservers and platforms.