Lost Password?

  #1 (permalink)  
Old 04-29-2008, 05:59 AM
Jaan's Avatar   
Jaan Jaan is offline
Moderator
 
Join Date: Dec 2006
Location: Estonia
Age: 17
Posts: 805
Last Blog:
Wadio Media Layout Com...
Rep Power: 14
Jaan is a jewel in the roughJaan is a jewel in the roughJaan is a jewel in the rough
Send a message via MSN to Jaan
Default Simple banner rotator

Okay today I'm going to show you how to make a simple banner rotator... You can use it for your ads on your site

First of all we must create tables to database:

SQL Code:
  1. CREATE TABLE `banner` (
  2.   `id` int(5) NOT NULL AUTO_INCREMENT,
  3.   `bannerimg` tinytext NOT NULL,
  4.   `bannerurl` varchar(100) NOT NULL,
  5.   `bannertxt` varchar(100) NOT NULL,
  6.   `views` int(5) NOT NULL DEFAULT '0',
  7.   PRIMARY KEY  (`id`)
  8. ) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;

Now we must start with our script..

PHP Code:
<?php
$SQLhost 
"localhost";
$SQLuser "";
$SQLpass "";
$DB "";
$SQLhost = "localhost"; - Here will be your SQL host, usually it's localhost but it can be something else also.. if you want to know what's your host.. contact with your hosting provider
$SQLuser = ""; - your database username
$SQLpass = ""; - your database password
$DB = ""; - Database

PHP Code:
mysql_connect($SQLhost$SQLuser$SQLpass) or die("Can not connect to database: ".mysql_error());
mysql_select_db($DB) or die("Can not select database: ".mysql_error()); 
mysql_connect($SQLhost, $SQLuser, $SQLpass) or die("Can not connect to database: ".mysql_error()); - This will connect to the database and if it can not connect, then it will generate a error message with details why you can't connect to your database
mysql_select_db($DB) or die("Can not select database: ".mysql_error()); - It will select a database for you.. but if it can't select it will generate a detailed error

Now let's find out how many banners we have in our database and let's generate a random number

PHP Code:
$query mysql_query("SELECT * FROM banner");
$numTab mysql_num_rows($query);
$RandNum = (rand()%$numTab);
$query mysql_query("SELECT * FROM banner LIMIT $RandNum, 1"); 
$query = mysql_query("SELECT * FROM banner"); - It will select all tables from banner table
$numTab = mysql_num_rows($query); - This will show us how many records are in our table

Another 2 rows will generate a random number and they will select random banner.

Now let's show our banner.

PHP Code:
while ($row mysql_fetch_array($query)){
$banURL $row['bannerurl'];
$banTXT $row['bannertxt'];
$Banner $row['bannerimg'];
$BanViews $row['views'];
$BanID $row['id'];

echo
"<a href='".$banURL."' target='_blank' title='".$banTXT."'><img src='".$banner."' alt='".$banTXT."' border='0'></a>";
$newViews $BanViews+1;
mysql_query("UPDATE banner SET views = $newViews WHERE id = $BanID");

while ($row = mysql_fetch_array($query)){ - Starts a while and get's info from the table
$banURL = $row['bannerurl']; - Banner's URL
$banTXT = $row['bannertxt']; - Banner's text
$Banner = $row['bannerimg']; - Banner itself
$BanViews = $row['views']; - Banner's views
$BanID = $row['id']; - Banner's ID

echo"<a href='".$banURL."' target='_blank' title='".$banTXT."'><img src='".$banner."' alt='".$banTXT."' border='0'></a>"; - Shows the banner that was randomly chosen from the table
$newViews = $BanViews+1; - Increases banner views by 1
mysql_query("UPDATE banner SET views = $newViews WHERE id = $BanID"); - Updates banner views

And we are done Simple 'eh
Okay here's the full script:

PHP Code:
<?php

$SQLhost 
"localhost";
$SQLuser "";
$SQLpass "";
$DB "";

mysql_connect($SQLhost$SQLuser$SQLpass) or die("Can not connect to database: ".mysql_error());
mysql_select_db($DB) or die("Can not select database: ".mysql_error());

$query mysql_query("SELECT * FROM banner");
$numTab mysql_num_rows($query);

$RandNum = (rand()%$numTab);
$query mysql_query("SELECT * FROM banner LIMIT $RandNum, 1");

while (
$row mysql_fetch_array($query)){
$banURL $row['bannerurl'];
$banTXT $row['bannertxt'];
$Banner $row['bannerimg'];
$BanViews $row['views'];
$BanID $row['id'];

echo
"<a href='".$banURL."' target='_blank' title='".$banTXT."'><img src='".$banner."' alt='".$banTXT."' border='0'></a>";
$newViews $BanViews+1;
mysql_query("UPDATE banner SET views = $newViews WHERE id = $BanID");
}

?>
Enjoy
__________________


Cheap & Professional Web Design | Need help? Send a PM
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

Sponsored Links
  #2 (permalink)  
Old 05-02-2008, 01:40 PM
Xav's Avatar   
Xav Xav is offline
Code Warrior
 
Join Date: Mar 2008
Location: London, England
Posts: 5,321
Last Blog:
Web slideshow in JavaS...
Rep Power: 45
Xav is a splendid one to beholdXav is a splendid one to beholdXav is a splendid one to beholdXav is a splendid one to beholdXav is a splendid one to beholdXav is a splendid one to beholdXav is a splendid one to behold
Send a message via MSN to Xav
Default Re: Simple banner rotator

I have just started learning PHP, and I am wondering - where do you insert the SQL code? Is it in a separate file, and if so, what sort of file?
__________________
[TRUTH] TcM is the best moderator ever! [/TRUTH]
"Valid XHTML is like sex - everybody claims to have the same goal, but everybody has their own tricks and results vary wildly."
Mr. Xav | Website | Forums | Blog
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 05-02-2008, 02:20 PM
John's Avatar   
John John is online now
Co-Administrator
 
Join Date: Jul 2006
Age: 19
Posts: 2,737
Last Blog:
Passwords
Rep Power: 20
John has much to be proud ofJohn has much to be proud ofJohn has much to be proud ofJohn has much to be proud ofJohn has much to be proud ofJohn has much to be proud ofJohn has much to be proud ofJohn has much to be proud ofJohn has much to be proud of
Send a message via AIM to John
Default Re: Simple banner rotator

Quote:
Originally Posted by Xav View Post
I have just started learning PHP, and I am wondering - where do you insert the SQL code? Is it in a separate file, and if so, what sort of file?
You insert it into your MySQL database.
__________________
CodeCall Blog | CodeCall Wiki | Shareware | Linux Forum | My Blog
Chat with other CodeCall members on IRC; connect to irc.codecall.net and join #codecall
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 05-18-2008, 07:34 PM
DevilsCharm's Avatar   
DevilsCharm DevilsCharm is offline
Programming God
 
Join Date: Jul 2006
Posts: 887
Rep Power: 13
DevilsCharm is on a distinguished road
Default Re: Simple banner rotator

Makes sense to insert SQL code into the MySQL database, indeed.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 05-20-2008, 02:33 PM
Xav's Avatar   
Xav Xav is offline
Code Warrior
 
Join Date: Mar 2008
Location: London, England
Posts: 5,321
Last Blog:
Web slideshow in JavaS...
Rep Power: 45
Xav is a splendid one to beholdXav is a splendid one to beholdXav is a splendid one to beholdXav is a splendid one to beholdXav is a splendid one to beholdXav is a splendid one to beholdXav is a splendid one to behold
Send a message via MSN to Xav
Default Re: Simple banner rotator

I didn't know what it was at the time. I'm still a little confused, actually. Is the MySQL database a separate file, or not? And what sort of file is it?
__________________
[TRUTH] TcM is the best moderator ever! [/TRUTH]
"Valid XHTML is like sex - everybody claims to have the same goal, but everybody has their own tricks and results vary wildly."
Mr. Xav | Website | Forums | Blog
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

Sponsored Links
  #6 (permalink)  
Old 05-21-2008, 07:35 AM
Jaan's Avatar   
Jaan Jaan is offline
Moderator
 
Join Date: Dec 2006
Location: Estonia
Age: 17
Posts: 805
Last Blog:
Wadio Media Layout Com...
Rep Power: 14
Jaan is a jewel in the roughJaan is a jewel in the roughJaan is a jewel in the rough
Send a message via MSN to Jaan
Default Re: Simple banner rotator


mysql database isnt a file
it's a database.. it's like server..
__________________


Cheap & Professional Web Design | Need help? Send a PM
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #7 (permalink)  
Old 05-21-2008, 02:09 PM
Xav's Avatar   
Xav Xav is offline
Code Warrior
 
Join Date: Mar 2008
Location: London, England
Posts: 5,321
Last Blog:
Web slideshow in JavaS...
Rep Power: 45
Xav is a splendid one to beholdXav is a splendid one to beholdXav is a splendid one to beholdXav is a splendid one to beholdXav is a splendid one to beholdXav is a splendid one to beholdXav is a splendid one to behold
Send a message via MSN to Xav
Default Re: Simple banner rotator

OOHHHH... I still don't get a couple of things. Presumably they're already made, as web hosting providers offer a set amount of databases. So why do you need to create them using sql_create_database(), if they're already there?
__________________
[TRUTH] TcM is the best moderator ever! [/TRUTH]
"Valid XHTML is like sex - everybody claims to have the same goal, but everybody has their own tricks and results vary wildly."
Mr. Xav | Website | Forums | Blog
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #8 (permalink)  
Old 05-22-2008, 06:13 AM
Jaan's Avatar   
Jaan Jaan is offline
Moderator
 
Join Date: Dec 2006
Location: Estonia
Age: 17
Posts: 805
Last Blog:
Wadio Media Layout Com...
Rep Power: 14
Jaan is a jewel in the roughJaan is a jewel in the roughJaan is a jewel in the rough
Send a message via MSN to Jaan
Default Re: Simple banner rotator

you can use this function also if you have permission..
BUT
usually you are not permitted to do it..
so..
you must create databases in your Cpanel or phpMyAdmin
__________________


Cheap & Professional Web Design | Need help? Send a PM
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #9 (permalink)  
Old 05-22-2008, 10:36 AM
Xav's Avatar   
Xav Xav is offline
Code Warrior
 
Join Date: Mar 2008
Location: London, England
Posts: 5,321
Last Blog:
Web slideshow in JavaS...
Rep Power: 45
Xav is a splendid one to beholdXav is a splendid one to beholdXav is a splendid one to beholdXav is a splendid one to beholdXav is a splendid one to beholdXav is a splendid one to beholdXav is a splendid one to behold
Send a message via MSN to Xav
Default Re: Simple banner rotator

Ok. I see now.
__________________
[TRUTH] TcM is the best moderator ever! [/TRUTH]
"Valid XHTML is like sex - everybody claims to have the same goal, but everybody has their own tricks and results vary wildly."
Mr. Xav | Website | Forums | Blog
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #10 (permalink)  
Old 05-22-2008, 01:21 PM
Jaan's Avatar   
Jaan Jaan is offline
Moderator
 
Join Date: Dec 2006
Location: Estonia
Age: 17
Posts: 805
Last Blog:
Wadio Media Layout Com...
Rep Power: 14
Jaan is a jewel in the roughJaan is a jewel in the roughJaan is a jewel in the rough
Send a message via MSN to Jaan
Default Re: Simple banner rotator

hmm.. you gave me an idea.. i'll create some tutorials about that
__________________


Cheap & Professional Web Design | Need help? Send a PM
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

Sponsored Links
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On