PHP implementation of the text database data display, add, modify, delete, query five basic methods of operation
I'm using a message. This program as an example, the implementation of PHP to the text database display, add, modify, delete, query five basic methods of operation.
This text database has a total of 10 fields: Customer IP, speaking time, customer name, customer email, customer homepage address, message expression image name, customer QQ, customer image, message content, administrator reply content.
1, Add Data Program section.
$date =date ("y-m-d h:i:s");//Get system time
$ip = $HTTP _server_vars[remote_addr]; IP address of the speaker
$text =encode ($GB _text);//Remove the space following the message.
$FP =fopen ("Gb.dat", "a");//Open the Gb.dat text file in write-only mode, and the file pointer points to the end of the file.
$str = $ip. "|". $date. "|". $GB _name. "|". $GB _email. "|". $GB _home. "|". $face. "|". $GB _qq. "|". $head. "|". $text. "|". $reply. " N//Assign the data of all messages to the variable $str, "|" The purpose of this is to use the data interval symbol for future data segmentation.
Fwrite ($fp, $STR);//write data to a file
Fclose ($FP);//Close file
ShowMessage ("Message success!", "index.php", "3");//Message success, 3 seconds after the automatic return to the main screen.
Among them, $gb_name, $GB _email, $GB _home, $face, $GB _qq, $head, $GB _text, $reply are data from the statement only son.
2. Data Display Program section
if (file_exists ("Gb.dat")) {//detect if file exists
$array =file ("Gb.dat");//reads the entire contents of the file into the array $array
$arr =array_reverse ($array);//$array The data in the row (i.e. the last line of the first row, and so on) reads into each cell of the array $arr ($arr [0] ... )。
$num =count ($array);//Gets the number of information in the array $array (a behavior one message)
if ($num >0) {//If the number of messages is greater than 0 (that is, the text database is not empty)
$total =ceil ($num/$pagesize);//Calculates the total number of pages (the largest integer, that is, where the decimal point is rounded up, $pagesize the amount of information displayed per page for a preset)
if ($page <1) {//If the current page digital number is less than 1
$page =1;//is assigned a value of 1
}
$number = ($page-1) * $pagesize;//Calculates the digital number of the first message currently displayed (digital number from zero, mainly to achieve the purpose of corresponding to the array unit number)
for ($i =0; $i <= $pagesize-1; $i) {//Enter loop
$row =explode ("|", $arr [$number]);//with "|" As a delimiter, splits the data for each of the cells in the array $arr and assigns the data to the array $rom
List ($ip, $datetime, $name, $email, $home, $face, $qq, $head, $text, $reply) = $row;//Assign the cell data in the array $row in order to the variable in parentheses
?>
>//Display image of customer
Nickname 】
Show Customer Name
Posted in: Show message release time
>//Display Customer Message emoticons image
Said: Show customer message Content
Show reply content
"target=" _blank "> Access Hyperlinks to the home//customer homepage
"> Gives Send//Customer e-mail connection
The QQ number is Show customer's QQ number
The IP address is "//Display the customer's IP address
"> Reply//message reply to the connection statement
"> Delete//message DELETE statement (with customer message time $datetime as deletion logo)
if ($number = = $num-1)//If the cell number of the array is equal to the total number of messages minus one (because the unit number starts with zero, so this means that this is the last message)
{
break;//jump out of the loop
}
$number = $number 1; Array cell number plus 1
http://www.bkjia.com/PHPjc/630929.html www.bkjia.com true http://www.bkjia.com/PHPjc/630929.html techarticle PHP Implementation of the text database data display, add, modify, delete, query five basic operations of the method I use a message this program as an example, the implementation of PHP to the text database ...