Today, I will follow the examples and find many errors. in order to give the Cainiao brothers a better understanding, I will show you the modified files. The data structure is as follows: CREATETABLEad (urlvarchar (100) NOTNULL, bannervarchar (150) NOTNULL, altvarchar (100), priorityint (4) DEFAULT1N today, I found many errors. to make the Cainiao brothers better understand them, I will show you the modified files.
The data structure is as follows:
Create table ad (
Url varchar (100) not null,
Banner varchar (150) not null,
Alt varchar (1, 100 ),
Priority int (4) DEFAULT '1' not null,
)
Add advertisement files
* ************** Putad. php ********************
// PHP program for processing form data;
// The banner name and link address of the image cannot be blank;
If (banner! = "") & (Url! = "")){
// If the ad link and image name have been used, you must select another one;
If (file_exists ("adbanner/". $ banner_name )){
Echo "ad Image. banner_name. Used. please select another one! ";
Exit;
};
// Upload the linked image file name to the adbanner directory;
Copy ($ banner, "adbanner/". $ banner_name );
// Connect to the MySQL database;
Include ("config. inc ");
// Insert new data from the form into the ad table;
$ Query = "insert into ad (url, alt, priority, banner) values ('$ url',' $ alt ',' $ priority ',' $ banner_name ')";
// If the insert operation is successful, the following information is displayed;
$ Try = mysql_query ($ query );
If ($ try ){
Echo "an advertisement has been added. Details :";
Echo "";
Echo "advertisement url: $ url
Ad link description: $ alt
Show weighting: $ priority ";
} Else {echo "error ";}
}
} Else {
?>
Untitled
Ad Exchange table
* ************** Showad. php ********************
Include ("config. inc ");
$ Query = "SELECT url, banner, alt, priority from ad ";
$ Result = mysql_query ($ query );
$ Numrows = mysql_num_rows ($ result );
// Use the mysql_fetch_object () function to obtain useful column information and store it in the corresponding array;
While ($ row = mysql_fetch_object ($ result )){
$ Adurl [] = $ row-> url;
$ Adbanner [] = $ row-> banner;
$ Adalt [] = $ row-> alt;
$ Adpriority [] = $ row-> priority;
}
// Initialize the intermediate variable;
$ Numcheck = $ numrows;
$ I = $ pricount = 0;
// Obtain the maximum random number;
While ($ numcheck ){
$ Pricount = $ adpriority [$ I];
$ I; $ numcheck --;
}
// Random seed is generated every one minute during program execution;
Srand (double) microtime () * 1000000 );
// Obtain a random number between 1 and the maximum random number;
$ Pri = rand (1, $ pricount );
// Clears the intermediate variable;
$ Pricount = 0;
// Different values are weighted to generate an array of elements used to display advertisements as strings;
For ($ I = 0; $ I <$ numrows; $ I ){
$ Pricount = $ adpriority [$ I];
If ($ pri <= $ pricount ){
$ Ad [] = "";
}
}
// Display the advertisement. the greater the weight, the greater the display opportunity;
Echo $ ad [0];
?>
Note: config. inc is used to connect to the mysql database, which is not listed here. There is still room for improvement in the above program, and there are still many functions not implemented. you can modify them if you want. But it is better to give me a copy after modification: terence611005@sina.com
If you have any questions, contact me: oicq: 18680986.