Home > Backend Development > PHP Tutorial > Use PHP to implement small site advertising management (revised version)_PHP tutorial

Use PHP to implement small site advertising management (revised version)_PHP tutorial

WBOY
Release: 2016-07-21 16:05:30
Original
830 people have browsed it

I followed the example today and found that there are many errors. In order to let the rookie brothers understand it better, I will show you the modified file.
The data structure is as follows:

CREATE TABLE ad (
url varchar(100) NOT NULL,
banner varchar(150) NOT NULL,
alt varchar(100),
priority int(4) DEFAULT '1' NOT NULL,
)

File to add advertisements
******************putad.php** ******************

// PHP program that processes form data; The image banner name and link address cannot be empty;
if (( banner!="") & ( url!="")) {
//If the advertising link and image name have been used, they must be selected separately;
if (file_exists("adbanner/". $banner_name)) {
echo "Ad image. banner_name. has been used, please choose another one!"";
exit;
};
//Upload the link image file name to the adbanner directory;
copy($banner,"adbanner/". $banner_name);
//Connect to MySQL Database;
include("config.inc");
//Insert new data from the form into the data table ad;
$query="insert into ad (url, alt, priority, banner ) values('$url','$alt','$priority','$banner_name')";
//If the insertion is successful, the following information will be displayed;
$try=mysql_query($query);
if($try){
echo "An advertisement has been added, detailed information: ";
echo "";
echo "Advertising URL: $url
Advertising link description: $alt
Display weighting: $priority ";
}else{echo "Error";}
}else{
?>

< head>
               Untitled
;/p>


Image URL:
< ;input type="file" name="banner">


Connect URL:


Display weight:


Connect Description:








< ;/form>



******************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 get useful The column information is stored in the corresponding array;
while($row = mysql_fetch_object($result)) {
$adurl[]=$row->url;
$adbanner[]=$row- >banner; > $numcheck=$numrows;
$i=$pricount=0;
//Get the maximum random number;
while($numcheck) {
$pricount+=$adpriority[$i];
       $i++; $numcheck--; 🎜> //Get a random number between 1 and the maximum random number;
$pri= rand(1,$pricount);
//The intermediate variables are cleared;
$pricount=0;
//According to different weighted values, generate an array whose elements are strings used to display advertisements;
for($i=0;$i<$numrows;$i++) {
$pricount+=$ adpriority[$i];
if ($pri<=$pricount) {
$ad[]="$adalt[$i]";
}
}
//Display ads, the greater the weight, the greater the display opportunity;
echo $ad[0];
?>


Note: inside config.inc It is what connects to the mysql database, so I won’t list it here. There is still room for improvement in the above program, and there are still many functions that have not been implemented. You can modify it if you want. However, it is best to give me a copy after modification: terence611005@sina.com
If you have any questions, please contact me: oicq:18680986

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/315702.htmlTechArticleI followed the example today and found that there are many mistakes in it. In order to let the rookie brothers understand better , I will show you the modified file. The data structure is as follows: CREAT...
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template