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:
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 ********************
<? If ($ submit ){
// PHP for processing form dataProgram;
// 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 {
?>
<HTML>
<Head>
<Title> untitled </title>
</Head>
<Body bgcolor = "# ffffff">
<P> ad exchange table </P>
<Form method = "Post" Action = "putad. php" enctype = "multipart/form-Data">
<P> image slice URL:
<Input type = "file" name = "banner">
</P>
<P> connection URL:
<Input type = "text" name = "url">
</P>
<P> display weight:
<Input type = "text" name = "Priority"> </P>
<P> connection description:
<Input type = "text" name = "Alt">
</P>
<P>
<Input type = "Submit" name = "Submit" value = "OK">
<Input type = "reset" name = "concel" value = "Refill">
</P>
</Form>
</Body>
</Html> <?}?>
* ************** 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 [] = "<a href = $ adurl [$ I]> </a> ";
}
}
// Display the advertisement. The greater the weight, the greater the display opportunity;
Echo $ AD [0];
?>
note: the config. inc file 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 best to give me a copy after modification: terence611005@sina.com
if you have any questions, please contact me: OICQ: 18680986